IAMのSESSION_START方法でNinjectと依存性注入が、今私は、Global.asaxの私のWebアプリケーションでninject.web拡張子を使用して、Webフォームアプリケーション
のSESSION_START方法に依存しreolving問題は、これが私のGlobal.asaxである必要がありデバッグを経て、私はことを見ても、
public class Global : NinjectHttpApplication
{
[Inject]
IUserManagement um { get; set; }
protected void Session_Start(object sender, EventArgs e)
{
if (WebUser.user != null)
{
if (HttpContext.Current.Session[ChiaveSessioneUtente] == null)
{
if (HttpContext.Current != null)
HttpContext.Current.Session.Add(ChiaveSessioneUtente, um.ResolveRequestingUser(Request));
}
}
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
RegisterServices(kernel);
return kernel;
}
private void RegisterServices(IKernel kernel)
{
var modules = new List<INinjectModule>
{
new BusinessLogicModule(),
};
kernel.Load(modules);
}
}
Ninjectモジュール
public class BusinessLogicModule : NinjectModule
{
public override void Load()
{
Bind<IBusinessInquiry>().To<BusinessInquiry>();
Bind<IUserManagement>().To<UserManagement>();
}
}
しかし、私は、アプリケーションを起動するum
、nullであります
NinjectWebCommon
でninject.webのnugetパッケージ版をお試し
Session_Start
前に実行されますが、結果は同じですので、問題は
私はあなたがサービスロケータを回避するための手立てを、あなたのカーネルを取得していないので、SESSION_START方法 –
内Resolveメソッドを呼び出すコードを追加する必要があります怖いですか?私はちょうど今サービスのロケータの方法を試してみてください、それはうまく動作しますが、きれいではありません... –
私はNinjectの実装に精通していませんが、私はasp.netに関連するいくつかのオブジェクトには、 HttpApplicationはそのリストにあります。これは、すべての扶養家族に注入できるエントリポイントですが、それ自体ではありません。あなたはそれを証明するためにNinjectのソースをチェックしなければならないかもしれません。 –