-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

4

1 回答 1

1

如果我正确理解了要求,这相当容易:

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);
              });
于 2017-03-05T09:03:09.050 回答