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();
c # inversion-of-control asp.net-mvc-5 autofac
jmm312
source share