【问题标题】:Ninject MVC3 & Web Forms. Am I doing this right?Ninject MVC3 和 Web 表单。我这样做对吗?
【发布时间】:2011-06-23 06:28:46
【问题描述】:

我有一个新的 MVC3 应用程序,其中包含一些旧版 Web 表单页面。我熟悉 Ninject 和 MVC,但我也想将 Ninject 与 Web 表单页面一起使用。我已经一起破解了一些东西,但我不确定这是否是解决这个问题的正确方法。

我已将 Ninject 内核公开如下:

public static IKernel Kernel { get { return CreateKernel(); } }

private static IKernel CreateKernel()
{
    var kernel = new StandardKernel();
    RegisterServices(kernel);
    return kernel;
}

然后,我为注入内核的 Web 表单页面创建了一个基类:

public class NinjectBase : Page
{
    public IKernel Kernel { get; private set; }
    public NinjectBase() { Kernel = NinjectMVC3.Kernel; } 
    public void Page_Init() { Kernel.Inject(this); }
}

这似乎运作良好。这种方法有什么问题吗?我还有其他方法可以解决这个问题吗?

【问题讨论】:

    标签: asp.net-mvc-3 ninject


    【解决方案1】:

    Ninject 2.4 将支持所有 Web 技术(ASP.NET、MVC、WCF)。

    如果您还没有投入生产,请获取 2.3.0.x

    您将需要 Ninject、Ninject.Web、Ninject.Web.Common、Nnject.Web.MVC3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-13
      • 2023-03-19
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 2015-06-09
      • 2014-06-28
      • 1970-01-01
      相关资源
      最近更新 更多