File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
extensions/Worker.Extensions.Http.AspNetCore/src/AspNetMiddleware Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -27,15 +27,25 @@ public async Task Invoke(HttpContext context)
27
27
28
28
FunctionContext functionContext = await _coordinator . SetHttpContextAsync ( invocationId , context ) ;
29
29
30
+ // Retrieve the existing service provider feature
31
+ var existingFeature = context . Features . Get < IServiceProvidersFeature > ( ) ;
32
+
30
33
// Explicitly set the RequestServices to prevent a new scope from being created internally.
31
34
// This also prevents the scope from being disposed when the request is complete. We want this to
32
35
// be disposed in the Functions middleware, not here.
33
- var servicesFeature = new RequestServicesFeature ( context , null )
36
+ await using var servicesFeature = new RequestServicesFeature ( context , null )
34
37
{
35
38
RequestServices = functionContext . InstanceServices
36
39
} ;
37
40
context . Features . Set < IServiceProvidersFeature > ( servicesFeature ) ;
38
41
39
- await _next ( context ) ;
42
+ try
43
+ {
44
+ await _next ( context ) ;
45
+ }
46
+ finally
47
+ {
48
+ context . Features . Set ( existingFeature ) ;
49
+ }
40
50
}
41
51
}
You can’t perform that action at this time.
0 commit comments