-1

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

whebz
  • 111
  • 3
  • 12

1 Answers1

1

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);
              });
zaitsman
  • 8,984
  • 6
  • 47
  • 79