![](/img/trans.png)
[英]Could not load file or assembly 'Ninject.Web' after Install MVC Forum Nuget Package
[英]Ninject.Web and user controls
我正在使用Ninject.Web庫和我們的Web表單應用程序。 它工作得很好,除了現在我需要將依賴注入到用戶控件中。 完成此任務的最佳方法是什么? Ninject.Web不包含與Web服務,頁面和母版頁類似的基類。
您可以自己為用戶控件創建基類:
public class NinjectedUserControl : System.Web.UI.UserControl
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RequestActivation();
}
/// <summary>
/// Asks the kernel to inject this instance.
/// </summary>
protected virtual void RequestActivation()
{
KernelContainer.Inject(this);
}
}
我在我的解決方案中有Ninject.Web的源代碼,我已將此類添加到Ninject.Web(因此它可以訪問內部的KernelContainer)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.