Ninject Alter Binding base on Owin.Context.User.Identy

74 Views Asked by At

I need to change ninject binding base on User.Identity.

I have this scenario: base on user Actor claim which I use for my own purpose. I have to inject on my class constructor the value of Claims.Actor, how can I do that?

public class C { 
    public C (string ActorValue) {
        // code here
    }
}

thanks

1

There are 1 best solutions below

0
zaitsman On BEST ANSWER

This is fairly easy, if i understood the requirement correctly:

kernel.Bind<C>().ToMethod(
            ctx =>
              {
                // you can also do anything like HttpContext.Current.GetOwinContext() etc..
                var id = HttpContext.Current?.User?.Identity?.Name ?? "not found";
                return new C(id);
              });