This repository was archived by the owner on Nov 20, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
Microsoft.AspNet.Http.Abstractions
test/Microsoft.AspNet.Http.Tests Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments