我看到以下两个示例用于注入用户的IPrincipal:MVC3 + Ninject:注入User IPrincipal的正确方法是什么?
方法1:
kernel.Bind<IPrincipal>()
.ToMethod(context => context.Kernel.Get<RequestContext>().HttpContext.User)
.InRequestScope();
方法2:
kernel.Bind<IPrincipal>()
.ToMethod(context => HttpContext.Current.User)
.InRequestScope();
有两个有什么区别?是首选吗?
如何使用Autofac完成上述操作? – lafama
找到我的答案http://stackoverflow.com/questions/2824649/passing-asp-net-user-by-dependency-injection – lafama
你需要使用Ninject.Web.Common for'InRequestScope'扩展方法 –