MVC3 + Ninject: What is the proper way to inject the User IPrincipal?

南楼画角 提交于 2019-12-23 07:55:40

问题


I have seen the following two example for injecting the User IPrincipal:

Method 1:

kernel.Bind<IPrincipal>()
   .ToMethod(context => context.Kernel.Get<RequestContext>().HttpContext.User)
   .InRequestScope();

Method 2:

kernel.Bind<IPrincipal>()
  .ToMethod(context => HttpContext.Current.User)
  .InRequestScope();

Is there any difference in the two? Is one preferred?


回答1:


The two methods are identical. Both are going to return the HttpContext obect for the current HTTP Request.



来源:https://stackoverflow.com/questions/7877415/mvc3-ninject-what-is-the-proper-way-to-inject-the-user-iprincipal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!