2017-02-27 44 views
-1

我需要根據User.Identity更改ninject綁定。Ninject Alter綁定基於Owin.Context.User.Identy

我有這種情況: 基於用戶Actor聲明,我用於我自己的目的。 我必須在我的類構造函數中注入Claims.Actor的值, 我該怎麼做?

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

感謝

回答

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); 
       });