MVC3 + Ninject:什么是注入用户的IPrincipal的正确方法? [英] MVC3 + Ninject: What is the proper way to inject the User IPrincipal?

查看:174
本文介绍了MVC3 + Ninject:什么是注入用户的IPrincipal的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了下面的两个例子注入用户的IPrincipal:

I have seen the following two example for injecting the 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();

有两个有什么区别?一个preferred?

推荐答案

这两种方法是相同的。两者都将返回HttpContext的obect当前HTTP请求。​​

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

这篇关于MVC3 + Ninject:什么是注入用户的IPrincipal的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆