私は Ninject から始めており、MVC 4 シナリオで使用し、「NinjectWebCommon」でバインディングを構成しました。そして、すべてがうまくいきます。
今、ライブラリで、MVC アプリからの構成でカーネルを取得したいと考えています。
例: 私の MVC プロジェクトには、プロパティを持つクラス "BaseController" があります。
[Inject]
public IKernel Ninject { get; set; }
完璧に動作します。つまり、BaseController から継承するコントローラーのすべてのアクションで、プロパティ「Ninject」が適切なインスタンスであり、null ではないことを意味します。
現在、外部ライブラリにまったく同じプロパティを持つクラス「NinjectProxy」がありますが、「NinjectProxy」の新しいインスタンスを作成するたびに、小道具「Ninject」はnullです!
public class NinjectProxy
{
[Inject]
public IKernel Ninject { get; set; }
public T Resolve<T>()
{
return Ninject.Get<T>();
}
}
私の完全なソリューションは次のようになります。
MVC app
- Reference on Common.dll and Ninject
- Contains ControllerBase
Common.dll
- This project contains the NinjectProxy class and have a reference on Ninject
- Here I want somehow get the kernel config that I configured in the mvc app to resolve dependecies
Implementation.dll
- References on Common.dll and Ninject
ライブラリは「NinjectWebCommon」に次のようにロードされます。
kernel.Load(Assembly.Load("lib"))
これが大事なら。
誰かが私が間違っていることを考えていますか?