开发者

Register HttpContext.User with Autofac

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜