diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs index 9b6c261392..241c3dd7a8 100644 --- a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs +++ b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs @@ -94,13 +94,22 @@ public static class AutofacRegistration throw new ArgumentNullException(nameof(services)); } - builder.RegisterType().As().ExternallyOwned(); + builder.RegisterType() + .As() + .As() + .ExternallyOwned(); + var autofacServiceScopeFactory = typeof(AutofacServiceProvider).Assembly.GetType("Autofac.Extensions.DependencyInjection.AutofacServiceScopeFactory"); if (autofacServiceScopeFactory == null) { throw new AbpException("Unable get type of Autofac.Extensions.DependencyInjection.AutofacServiceScopeFactory!"); } - builder.RegisterType(autofacServiceScopeFactory).As(); + + // Issue #83: IServiceScopeFactory must be a singleton and scopes must be flat, not hierarchical. + builder + .RegisterType(autofacServiceScopeFactory) + .As() + .SingleInstance(); Register(builder, services, lifetimeScopeTagForSingletons); } diff --git a/framework/src/Volo.Abp.Autofac/Volo.Abp.Autofac.csproj b/framework/src/Volo.Abp.Autofac/Volo.Abp.Autofac.csproj index 7ce82c1c9e..d8d2b83e5a 100644 --- a/framework/src/Volo.Abp.Autofac/Volo.Abp.Autofac.csproj +++ b/framework/src/Volo.Abp.Autofac/Volo.Abp.Autofac.csproj @@ -15,8 +15,8 @@ - - + +