Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 927
Shawn Avatar asked Oct 24 '11 14:10

Shawn


1 Answers

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

like image 150
Jeff Reddy Avatar answered Oct 15 '22 16:10

Jeff Reddy