Skip to main content
Bumped by Community user
Bumped by Community user
Highlighted words to ease understanding and improved formatting, added tag.
Source Link

We are currently doing sitecore upgrade and but there are something broken with autofac DIautofac DI integration with sitecore. we created our own serviceProviderBuilder which extends Sitecore.DependencyInjection.BaseServiceProviderBuilderSitecore.DependencyInjection.BaseServiceProviderBuilder, we then patch it through sitecore config, but it throws runtime errors "[LockRecursionException: Recursive read lock acquisitions not allowed in this mode.]"

[LockRecursionException: Recursive read lock acquisitions not allowed in this mode.]

Our custom service provider builder as shown in below

public class AutofacServiceProviderBuilder : Sitecore.DependencyInjection.BaseServiceProviderBuilder
    {
        protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
        {
            var builder = new ContainerBuilder();

            builder.Populate(serviceCollection);

            // Register All Controllers In The Current Scope
            builder.RegisterControllers(AppDomain.CurrentDomain.GetAssemblies());
            builder.RegisterApiControllers(AppDomain.CurrentDomain.GetAssemblies());

            // Register Modules
            builder.RegisterType<MemberOnlineMediatorService>().As<IMemberOnlineMediator>();
            builder.RegisterType<InteractionMaintenanceService>().As<IInteractionMaintenanceService>();
            builder.RegisterType<MemberStatementsService>().As<IMemberStatementsService>();
            builder.RegisterType<DbHealthCheckService>().As<IDbHealthCheckService>();

            // Register all Autofac Modules from assemblies
            builder.RegisterAssemblyModules(AppDomainScanner.AllAssemblies);
            
            builder.RegisterFilterProvider();

            // Register AutoMapper
            AutoMapperConfiguration(builder);

            // Register Additional Dependencies
            RegisterAbstractValidators(builder);

            // Build container
            var container = builder.Build();
            return new AutofacServiceProvider(container);
        }
    }

We are currently doing sitecore upgrade and but there are something broken with autofac DI integration with sitecore. we created our own serviceProviderBuilder which extends Sitecore.DependencyInjection.BaseServiceProviderBuilder, we then patch it through sitecore config, but it throws runtime errors "[LockRecursionException: Recursive read lock acquisitions not allowed in this mode.]"

Our custom service provider builder as shown in below

public class AutofacServiceProviderBuilder : Sitecore.DependencyInjection.BaseServiceProviderBuilder
    {
        protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
        {
            var builder = new ContainerBuilder();

            builder.Populate(serviceCollection);

            // Register All Controllers In The Current Scope
            builder.RegisterControllers(AppDomain.CurrentDomain.GetAssemblies());
            builder.RegisterApiControllers(AppDomain.CurrentDomain.GetAssemblies());

            // Register Modules
            builder.RegisterType<MemberOnlineMediatorService>().As<IMemberOnlineMediator>();
            builder.RegisterType<InteractionMaintenanceService>().As<IInteractionMaintenanceService>();
            builder.RegisterType<MemberStatementsService>().As<IMemberStatementsService>();
            builder.RegisterType<DbHealthCheckService>().As<IDbHealthCheckService>();

            // Register all Autofac Modules from assemblies
            builder.RegisterAssemblyModules(AppDomainScanner.AllAssemblies);
            
            builder.RegisterFilterProvider();

            // Register AutoMapper
            AutoMapperConfiguration(builder);

            // Register Additional Dependencies
            RegisterAbstractValidators(builder);

            // Build container
            var container = builder.Build();
            return new AutofacServiceProvider(container);
        }
    }

We are currently doing sitecore upgrade and but there are something broken with autofac DI integration with sitecore. we created our own serviceProviderBuilder which extends Sitecore.DependencyInjection.BaseServiceProviderBuilder, we then patch it through sitecore config, but it throws runtime errors

[LockRecursionException: Recursive read lock acquisitions not allowed in this mode.]

Our custom service provider builder as shown in below

public class AutofacServiceProviderBuilder : Sitecore.DependencyInjection.BaseServiceProviderBuilder
    {
        protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
        {
            var builder = new ContainerBuilder();

            builder.Populate(serviceCollection);

            // Register All Controllers In The Current Scope
            builder.RegisterControllers(AppDomain.CurrentDomain.GetAssemblies());
            builder.RegisterApiControllers(AppDomain.CurrentDomain.GetAssemblies());

            // Register Modules
            builder.RegisterType<MemberOnlineMediatorService>().As<IMemberOnlineMediator>();
            builder.RegisterType<InteractionMaintenanceService>().As<IInteractionMaintenanceService>();
            builder.RegisterType<MemberStatementsService>().As<IMemberStatementsService>();
            builder.RegisterType<DbHealthCheckService>().As<IDbHealthCheckService>();

            // Register all Autofac Modules from assemblies
            builder.RegisterAssemblyModules(AppDomainScanner.AllAssemblies);
            
            builder.RegisterFilterProvider();

            // Register AutoMapper
            AutoMapperConfiguration(builder);

            // Register Additional Dependencies
            RegisterAbstractValidators(builder);

            // Build container
            var container = builder.Build();
            return new AutofacServiceProvider(container);
        }
    }
Source Link

Autofac DI with Sitecore 10.3

We are currently doing sitecore upgrade and but there are something broken with autofac DI integration with sitecore. we created our own serviceProviderBuilder which extends Sitecore.DependencyInjection.BaseServiceProviderBuilder, we then patch it through sitecore config, but it throws runtime errors "[LockRecursionException: Recursive read lock acquisitions not allowed in this mode.]"

Our custom service provider builder as shown in below

public class AutofacServiceProviderBuilder : Sitecore.DependencyInjection.BaseServiceProviderBuilder
    {
        protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
        {
            var builder = new ContainerBuilder();

            builder.Populate(serviceCollection);

            // Register All Controllers In The Current Scope
            builder.RegisterControllers(AppDomain.CurrentDomain.GetAssemblies());
            builder.RegisterApiControllers(AppDomain.CurrentDomain.GetAssemblies());

            // Register Modules
            builder.RegisterType<MemberOnlineMediatorService>().As<IMemberOnlineMediator>();
            builder.RegisterType<InteractionMaintenanceService>().As<IInteractionMaintenanceService>();
            builder.RegisterType<MemberStatementsService>().As<IMemberStatementsService>();
            builder.RegisterType<DbHealthCheckService>().As<IDbHealthCheckService>();

            // Register all Autofac Modules from assemblies
            builder.RegisterAssemblyModules(AppDomainScanner.AllAssemblies);
            
            builder.RegisterFilterProvider();

            // Register AutoMapper
            AutoMapperConfiguration(builder);

            // Register Additional Dependencies
            RegisterAbstractValidators(builder);

            // Build container
            var container = builder.Build();
            return new AutofacServiceProvider(container);
        }
    }