Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit f931cb7

Browse files
committed
Moving httpcontextfactory to AspNet.Http.Abstractions
1 parent bcb56bd commit f931cb7

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Http.Features;
5+
6+
namespace Microsoft.AspNet.Http
7+
{
8+
public interface IHttpContextFactory
9+
{
10+
HttpContext CreateHttpContext(IFeatureCollection featureCollection);
11+
void Dispose(HttpContext httpContext);
12+
}
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Http.Features;
5+
6+
namespace Microsoft.AspNet.Http.Internal
7+
{
8+
public class HttpContextFactory : IHttpContextFactory
9+
{
10+
private IHttpContextAccessor _httpContextAccessor;
11+
12+
public HttpContextFactory(IHttpContextAccessor httpContextAccessor)
13+
{
14+
_httpContextAccessor = httpContextAccessor;
15+
}
16+
17+
public HttpContext CreateHttpContext(IFeatureCollection featureCollection)
18+
{
19+
var httpContext = new DefaultHttpContext(featureCollection);
20+
_httpContextAccessor.HttpContext = httpContext;
21+
return httpContext;
22+
}
23+
24+
public void Dispose(HttpContext httpContext)
25+
{
26+
_httpContextAccessor.HttpContext = null;
27+
}
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Http.Features;
5+
using Xunit;
6+
7+
namespace Microsoft.AspNet.Http.Internal
8+
{
9+
public class HttpContextFactoryTests
10+
{
11+
[Fact]
12+
public void CreateHttpContextSetsHttpContextAccessor()
13+
{
14+
// Arrange
15+
var accessor = new HttpContextAccessor();
16+
var contextFactory = new HttpContextFactory(accessor);
17+
18+
// Act
19+
var context = contextFactory.CreateHttpContext(new FeatureCollection());
20+
21+
// Assert
22+
Assert.True(ReferenceEquals(context, accessor.HttpContext));
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)