I Have the following registrations:
builder
.RegisterAssemblyTypes(assemblies)
.Where(t => t.GetCustomAttributes(typeof(IocContainerMarkerAttribute), false).Any()
&& ((IocContainerMarkerAttribute)t.GetCustomAttribute(typeof(IocContainerMarkerAttribute))).IsSingleInstance == false)
.AsImplementedInterfaces()
.InstancePerRequest()
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
builder
.RegisterAssemblyTypes(assemblies)
.Where(t => t.GetCustomAttributes(typeof(IocContainerMarkerAttribute), false).Any()
&& ((IocContainerMarkerAttribute)t.GetCustomAttribute(typeof(IocContainerMarkerAttribute))).IsSingleInstance)
.AsImplementedInterfaces()
.SingleInstance()
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
And I am trying to request the following dependency:
[IocContainerMarker(false)]
public class SecurityProvider : ISecurityProvider
{}
Like this:
ar authenticationSecurityProvider = (ISecurityProvider)request.GetDependencyScope().GetService(typeof(ISecurityProvider));
If I comment the second registration build block it works fine but if I uncomment it, I get the following exception:
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.
It seems like a fairly common thing to do, so what am I missing here?
Thanks
UPDATE
The problem seems to be another one. I need a singleton dependency to be injected into a InstancePerRequest one.