File tree Expand file tree Collapse file tree
Libraries/src/Amazon.Lambda.AspNetCoreServer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -320,9 +320,14 @@ private void AddRegisterBeforeSnapshot()
320320
321321 for ( var i = 0 ; i < invokeTimes ; i ++ )
322322 {
323+ // Create a scope to properly handle scoped services (e.g., IAuthenticationHandlerProvider)
324+ // This matches the behavior in FunctionHandlerAsync and prevents InvalidOperationException
325+ // when resolving scoped services in Development mode where scope validation is enabled.
326+ using var scope = _hostServices . CreateScope ( ) ;
327+
323328 InvokeFeatures features = new InvokeFeatures ( ) ;
324329 ( features as IItemsFeature ) . Items = new Dictionary < object , object > ( ) ;
325- ( features as IServiceProvidersFeature ) . RequestServices = _hostServices ;
330+ ( features as IServiceProvidersFeature ) . RequestServices = scope . ServiceProvider ;
326331
327332 MarshallRequest ( features , request , new SnapStartEmptyLambdaContext ( ) ) ;
328333
You can’t perform that action at this time.
0 commit comments