开发者

Register HttpContext.User with Autofac

开发者 https://www.devze.com 2023-02-15 12:19 出处:网络
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>()

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

精彩评论

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

关注公众号