I would like to do the following in Autofac, but not sure how?
This is how you do it in StructureMap
For开发者_JAVA技巧RequestedType<IPrincipal>()
.CacheBy(InstanceScope.Hybrid)
.TheDefault.Is.ConstructedBy(ctx => HttpContext.Current.User);
For ASP.NET MVC 1 and 2:
builder.Register(c => HttpContext.Current.User).HttpRequestScoped();
For ASP.NET MVC 3:
builder.Register(c => HttpContext.Current.User).InstancePerHttpRequest();
For Autofac ASP.NET MVC3 integration you may take a look at the documentation (updated link).
For ASP.NET MVC 5:
builder.Register(c => HttpContext.Current.User).InstancePerRequest();
精彩评论