Skip to content

Commit 2a289ed

Browse files
committed
Fix snapstart scope issue
1 parent 9ea4482 commit 2a289ed

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)