Resolution Problem with HttpRequestScoped in Autofac

Posted by Page Brooks on Stack Overflow See other posts from Stack Overflow or by Page Brooks
Published on 2010-04-20T04:17:43Z Indexed on 2010/04/20 4:23 UTC
Read the original article Hit count: 444

Filed under:
|
|

I'm trying to resolve the AccountController in my application, but it seems that I have a lifetime scoping issue.

builder.Register(c => new MyDataContext(connectionString)).As<IDatabase>().HttpRequestScoped();
builder.Register(c => new UnitOfWork(c.Resolve<IDatabase>())).As<IUnitOfWork>().HttpRequestScoped();
builder.Register(c => new AccountService(c.Resolve<IDatabase>())).As<IAccountService>().InstancePerLifetimeScope();
builder.Register(c => new AccountController(c.Resolve<IAccountService>())).InstancePerDependency();

I need MyDataContext and UnitOfWork to be scoped at the HttpRequestLevel. When I try to resolve the AccountController, I get the following error:

No scope matching the expression 'value(Autofac.Builder.RegistrationBuilder`3+<>c__DisplayClass0[...]).lifetimeScopeTag.Equals(scope.Tag)' is visible from the scope in which the instance was requested.

Do I have my dependency lifetimes set up incorrectly?

© Stack Overflow or respective owner

Related posts about autofac

Related posts about ASP.NET