Moving httpcontextfactory to AspNet.Http.Abstractions
This commit is contained in:
parent
bcb56bdd1a
commit
f931cb7c6d
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
public interface IHttpContextFactory
|
||||
{
|
||||
HttpContext CreateHttpContext(IFeatureCollection featureCollection);
|
||||
void Dispose(HttpContext httpContext);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Internal
|
||||
{
|
||||
public class HttpContextFactory : IHttpContextFactory
|
||||
{
|
||||
private IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public HttpContextFactory(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public HttpContext CreateHttpContext(IFeatureCollection featureCollection)
|
||||
{
|
||||
var httpContext = new DefaultHttpContext(featureCollection);
|
||||
_httpContextAccessor.HttpContext = httpContext;
|
||||
return httpContext;
|
||||
}
|
||||
|
||||
public void Dispose(HttpContext httpContext)
|
||||
{
|
||||
_httpContextAccessor.HttpContext = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Internal
|
||||
{
|
||||
public class HttpContextFactoryTests
|
||||
{
|
||||
[Fact]
|
||||
public void CreateHttpContextSetsHttpContextAccessor()
|
||||
{
|
||||
// Arrange
|
||||
var accessor = new HttpContextAccessor();
|
||||
var contextFactory = new HttpContextFactory(accessor);
|
||||
|
||||
// Act
|
||||
var context = contextFactory.CreateHttpContext(new FeatureCollection());
|
||||
|
||||
// Assert
|
||||
Assert.True(ReferenceEquals(context, accessor.HttpContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue