【问题标题】:Error with Ninject MVC 2 extension - CreateKernel()Ninject MVC 2 扩展出错 - CreateKernel()
【发布时间】:2012-05-06 08:53:33
【问题描述】:

我的 Global.asax.cs 中有以下内容:

using System.Web.Mvc;
using System.Web.Routing;
using HandiGamer.WebUI.ConditionalValidation;
using HandiGamer.Domain.Concrete;
using Ninject;
using Ninject.Web.Common;
using System.Reflection;
using HandiGamer.Domain.Abstract; 

//namespace....

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("favicon.ico");

        routes.MapRoute(
            null,
            "Reviews/{id}",
            new { controller = "Reviews", action = "ShowReviewById" },
            new { id = @"\d+" }
        );

        routes.MapRoute(
            null,
            "Reviews/Latest",
            new { controller = "Reviews", action = "Latest"}
        );

        routes.MapRoute(
            null,
            "Reviews/{slug}",
            new { controller = "Reviews", action = "ShowReviewBySlug" },
            new { slug = @"[0-9a-zA-Z\-]+" }
        );

        routes.MapRoute(
            null,
            "News/{id}",
            new { controller = "News", action = "ShowNewsById" },
            new { id = @"\d+" }
        );

        routes.MapRoute(
            null,
            "News/{slug}",
            new { controller = "News", action = "ShowNewsBySlug" },
            new { slug = @"[0-9a-zA-Z\-]" }
        );

        routes.MapRoute(
            null,
            "Articles/{id}",
            new { controller = "Articles", action = "ShowArticleById" },
            new { id = @"\d+" }
        );

        routes.MapRoute(
            null,
            "Articles/{slug}",
            new { controller = "Articles", action = "ShowArticleBySlug" },
            new { slug = @"[0-9a-zA-Z\-]" }
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

        routes.MapRoute(
            null,
            "{*path}",
            new { controller = "Error", action = "Http404" }
        );
    }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);
        DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
        DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RequiredIfAttribute), typeof(RequiredIfValidator));
    }

    protected override IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        kernel.Bind<IArticleRepository>().To<HGArticleRepository>();
        kernel.Bind<IGameRepository>().To<HGGameRepository>();
        kernel.Bind<INewsRepository>().To<HGNewsRepository>();
        kernel.Load(Assembly.GetExecutingAssembly());
        return kernel;
    }
}

但是在构建我的解决方案时,我收到以下错误:

Error 1 'HandiGamer.MvcApplication.CreateKernel()': no suitable method found to override C:\Users\Kevin\documents\visual studio 2010\Projects\HandiGamer\HandiGamer\Global.asax.cs 92 36 HandiGamer.WebUI

有什么想法吗?我几乎复制了 github 示例应用程序中的内容,所以我很难过。

【问题讨论】:

    标签: c#-4.0 asp.net-mvc-2 ninject.web.mvc


    【解决方案1】:

    你必须从 NinjectHttpAplication 派生

    【讨论】:

    • 天啊!我知道这对我来说一定是愚蠢的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多