Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top