Autofac.Extensions.DependencyInjection: IServiceScopeFactory should be a singleton; service scopes should not be nested

Describe the bug If AutofacServiceScopeFactory is transient, that will not compatible with Ms DI.

To reproduce

if (provider.GetService<IServiceScopeFactory>() == provider.GetService<IServiceScopeFactory>())
{
    //Ms DI.
}
else
{
    //Autofac
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I’m with you @tillig; my vote is for breaking change, switch to a flat conforming hierarchy in this integration. If people want nested scopes, they’ve gone outside the (apparent) bounds of MSDI and should be using Autofac anyway.

This looks like something I need to file with the .NET Core folks because their compatibility tests don’t indicate that the service scope factory must be a singleton, which indicates there’s actually a bug in the docs recommending this path and not necessarily a bug that Autofac has to fix. I’ll link that issue when I get a chance to file it.