ASP.NET MVC5: Not a single area with a tag matching "AutofacWebRequest" is visible from the scope

I am facing an error in my ASP.NET MVC 5 application using autofac v3.5.0, Autofac.Extras.CommonServiceLocator v3.2.0, Autofac.Mvc5 v3.3.2 all with targetframework net45:

No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

when trying to convert the following Windsor Rhino-Security mapping:

 WindsorServiceLocator windsorServiceLocator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); container.Register( Component.For<IAuthorizationService>() .ImplementedBy<AuthorizationService>() .Lifestyle.Is(Lifestyle.Transient), Component.For<IAuthorizationRepository>() .ImplementedBy<AuthorizationRepository>() .Lifestyle.Is(Lifestyle.Transient), Component.For<IPermissionsBuilderService>() .ImplementedBy<PermissionsBuilderService>() .Lifestyle.Is(Lifestyle.Transient), Component.For<IPermissionsService>() .ImplementedBy<PermissionsService>() .Lifestyle.Is(Lifestyle.Transient) ); 

to autofocus display. The first 4 comparisons work without any problems, but the latter causes the above error. I traced the first instance where the error occurs on this line: https://github.com/hibernating-rhinos/rhino-security/blob/master/Rhino.Security/Security.cs#L34

 builder.RegisterType<AuthorizationService>().As<IAuthorizationService>().InstancePerDependency(); builder.RegisterType<AuthorizationRepository>().As<IAuthorizationRepository>().InstancePerDependency(); builder.RegisterType<PermissionsBuilderService>().As<IPermissionsBuilderService>().InstancePerDependency(); builder.RegisterType<PermissionsService>().As<IPermissionsService>().InstancePerDependency(); // Everything works except this builder.RegisterType<OrganizationInformationExtractor>().As<IEntityInformationExtractor<Organization>>().InstancePerDependency(); 
+8
c # inversion-of-control asp.net-mvc-5 autofac
source share
1 answer

Check all the parameters that are required for the OrganizationInformationExtractor parameter. One of these parameters is either not registered in autofac or not registered as InstancePerDependency. It worked for me.

+1
source share

All Articles