In my setup class I have the following code (using Autofac and the MVC Web API Template in Visual Studio)
builder.RegisterType<CRMUserStore<IdentityUser>>().As<IUserLoginStore<IdentityUser>>()
.InstancePerRequest();
Then in the Startup.Auth class I have the following
UserManagerFactory = () => new UserManager<IdentityUser>(
DependencyResolver.Current.GetService<IUserLoginStore<IdentityUser>>());
This returns null. Then when I try instead of the above
UserManagerFactory = () => new UserManager<IdentityUser>(
_container.Resolve<IUserLoginStore<IdentityUser>>()); //_container is IContainer
I get an error saying
An exception of type 'Autofac.Core.DependencyResolutionException' occurred in Autofac.dll but was not handled in user code
Additional information: 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.
How do I fix this?