I am using AutoFac 3.5 with integration of WebApi 3.3 and Asp.Identity 2.0.1. The problem is that Identity Asp.Net has a problem when im specyfing MyDbContext as InstancePerRequest. Then I got this error:
No area with a tag matching "AutofacWebRequest" is visible from the area in which the instance was requested. This usually indicates that the component registered as an HTTP request is requested by the SingleInstance () component (or a similar script). As part of web integration, dependencies on DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime are always requested, never from the container itself,
I am registering an Asp token provider as follows:
public partial class Startup
{
static Startup()
{
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/token"),
RefreshTokenProvider = (IAuthenticationTokenProvider)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IAuthenticationTokenProvider)),
Provider = (IOAuthAuthorizationServerProvider)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IOAuthAuthorizationServerProvider)),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromHours(1),
AllowInsecureHttp = true
};
}
public void ConfigureAuth(IAppBuilder app)
{
app.UseOAuthBearerTokens(OAuthOptions);
}
}
And the AutoFac part looks like this:
builder.RegisterType<MyDbContext>().As<DbContext>().InstancePerRequest();
builder.RegisterType<SimpleRefreshToken>().As<IAuthenticationTokenProvider>();
builder.Register(x => new ApplicationOAuthProvider(
"self",
x.Resolve<Func<UserManager<User>>>()).As<IOAuthAuthorizationServerProvider>();
- ? ASP.net, IoC DbContext
http://blogs.msdn.com/b/webdev/archive/2014/02/12/per-request-lifetime-management-for-usermanager-class-in-asp-net-identity.aspx