@@ -17,7 +17,6 @@ public class CorsMiddleware
17
17
{
18
18
private readonly Func < object , Task > OnResponseStartingDelegate = OnResponseStarting ;
19
19
private readonly RequestDelegate _next ;
20
- private readonly ICorsPolicyProvider _corsPolicyProvider ;
21
20
private readonly CorsPolicy _policy ;
22
21
private readonly string _corsPolicyName ;
23
22
@@ -26,61 +25,12 @@ public class CorsMiddleware
26
25
/// </summary>
27
26
/// <param name="next">The next middleware in the pipeline.</param>
28
27
/// <param name="corsService">An instance of <see cref="ICorsService"/>.</param>
29
- /// <param name="policyProvider">A policy provider which can get an <see cref="CorsPolicy"/>.</param>
30
- [ Obsolete ( "This constructor has been replaced with an equivalent constructor which requires an ILoggerFactory" ) ]
31
- public CorsMiddleware (
32
- RequestDelegate next ,
33
- ICorsService corsService ,
34
- ICorsPolicyProvider policyProvider )
35
- : this ( next , corsService , policyProvider , NullLoggerFactory . Instance , policyName : null )
36
- {
37
- }
38
-
39
- /// <summary>
40
- /// Instantiates a new <see cref="CorsMiddleware"/>.
41
- /// </summary>
42
- /// <param name="next">The next middleware in the pipeline.</param>
43
- /// <param name="corsService">An instance of <see cref="ICorsService"/>.</param>
44
- /// <param name="policyProvider">A policy provider which can get an <see cref="CorsPolicy"/>.</param>
45
- /// <param name="policyName">An optional name of the policy to be fetched.</param>
46
- [ Obsolete ( "This constructor has been replaced with an equivalent constructor which requires an ILoggerFactory" ) ]
47
- public CorsMiddleware (
48
- RequestDelegate next ,
49
- ICorsService corsService ,
50
- ICorsPolicyProvider policyProvider ,
51
- string policyName )
52
- : this ( next , corsService , policyProvider , NullLoggerFactory . Instance , policyName )
53
- {
54
- }
55
-
56
- /// <summary>
57
- /// Instantiates a new <see cref="CorsMiddleware"/>.
58
- /// </summary>
59
- /// <param name="next">The next middleware in the pipeline.</param>
60
- /// <param name="corsService">An instance of <see cref="ICorsService"/>.</param>
61
- /// <param name="policy">An instance of the <see cref="CorsPolicy"/> which can be applied.</param>
62
- [ Obsolete ( "This constructor has been replaced with an equivalent constructor which requires an ILoggerFactory" ) ]
63
- public CorsMiddleware (
64
- RequestDelegate next ,
65
- ICorsService corsService ,
66
- CorsPolicy policy )
67
- : this ( next , corsService , policy , NullLoggerFactory . Instance )
68
- {
69
- }
70
-
71
- /// <summary>
72
- /// Instantiates a new <see cref="CorsMiddleware"/>.
73
- /// </summary>
74
- /// <param name="next">The next middleware in the pipeline.</param>
75
- /// <param name="corsService">An instance of <see cref="ICorsService"/>.</param>
76
- /// <param name="policyProvider">A policy provider which can get an <see cref="CorsPolicy"/>.</param>
77
28
/// <param name="loggerFactory">An instance of <see cref="ILoggerFactory"/>.</param>
78
29
public CorsMiddleware (
79
30
RequestDelegate next ,
80
31
ICorsService corsService ,
81
- ICorsPolicyProvider policyProvider ,
82
32
ILoggerFactory loggerFactory )
83
- : this ( next , corsService , policyProvider , loggerFactory , policyName : null )
33
+ : this ( next , corsService , loggerFactory , policyName : null )
84
34
{
85
35
}
86
36
@@ -89,13 +39,11 @@ public CorsMiddleware(
89
39
/// </summary>
90
40
/// <param name="next">The next middleware in the pipeline.</param>
91
41
/// <param name="corsService">An instance of <see cref="ICorsService"/>.</param>
92
- /// <param name="policyProvider">A policy provider which can get an <see cref="CorsPolicy"/>.</param>
93
42
/// <param name="loggerFactory">An instance of <see cref="ILoggerFactory"/>.</param>
94
43
/// <param name="policyName">An optional name of the policy to be fetched.</param>
95
44
public CorsMiddleware (
96
45
RequestDelegate next ,
97
46
ICorsService corsService ,
98
- ICorsPolicyProvider policyProvider ,
99
47
ILoggerFactory loggerFactory ,
100
48
string policyName )
101
49
{
@@ -109,19 +57,13 @@ public CorsMiddleware(
109
57
throw new ArgumentNullException ( nameof ( corsService ) ) ;
110
58
}
111
59
112
- if ( policyProvider == null )
113
- {
114
- throw new ArgumentNullException ( nameof ( policyProvider ) ) ;
115
- }
116
-
117
60
if ( loggerFactory == null )
118
61
{
119
62
throw new ArgumentNullException ( nameof ( loggerFactory ) ) ;
120
63
}
121
64
122
65
_next = next ;
123
66
CorsService = corsService ;
124
- _corsPolicyProvider = policyProvider ;
125
67
_corsPolicyName = policyName ;
126
68
Logger = loggerFactory . CreateLogger < CorsMiddleware > ( ) ;
127
69
}
@@ -170,19 +112,19 @@ public CorsMiddleware(
170
112
private ILogger Logger { get ; }
171
113
172
114
/// <inheritdoc />
173
- public Task Invoke ( HttpContext context )
115
+ public Task Invoke ( HttpContext context , ICorsPolicyProvider corsPolicyProvider )
174
116
{
175
117
if ( ! context . Request . Headers . ContainsKey ( CorsConstants . Origin ) )
176
118
{
177
119
return _next ( context ) ;
178
120
}
179
121
180
- return InvokeCore ( context ) ;
122
+ return InvokeCore ( context , corsPolicyProvider ) ;
181
123
}
182
124
183
- private async Task InvokeCore ( HttpContext context )
125
+ private async Task InvokeCore ( HttpContext context , ICorsPolicyProvider corsPolicyProvider )
184
126
{
185
- var corsPolicy = _policy ?? await _corsPolicyProvider ? . GetPolicyAsync ( context , _corsPolicyName ) ;
127
+ var corsPolicy = _policy ?? await corsPolicyProvider . GetPolicyAsync ( context , _corsPolicyName ) ;
186
128
if ( corsPolicy == null )
187
129
{
188
130
Logger ? . NoCorsPolicyFound ( ) ;
0 commit comments