BanksySan
BanksySan

Reputation: 28500

NinjectHttpApplication.cs not found

I'm trying to make a simple "Hello World" using MVC4 and Ninject.

I'm following: this tutorial

I'm using MVC4 and Visual Studio 2012 Web Express and I've installed the Nuget package using the following:

Install-package Ninject
Install-package Ninject.MVC3

I've got the following global.aspx:

public class MvcApplication : Ninject.Web.Common.NinjectHttpApplication
{
    protected override Ninject.IKernel CreateKernel()
    {
        IKernel kernal = new StandardKernel();
        kernal.Load(Assembly.GetExecutingAssembly());
        kernal.Bind<IMessageService>().To<MessageService>();
        return kernal;
    }

    protected override void OnApplicationStarted()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();
    }
}

When I run this I find that I get an exception thrown: Sequence contains no elements and VS tries to open the file NinjectHttpApplication.cs for debugging. VS can't find it though.

Any idea what's going on here?

Thanks

Dave

UPDATE

I've just tried the solution given in this question, which is to move the registering bindings to the the file in App_Start, this file was NinjectWebCommon.cs in my folder, there is no NinjectMVC3.cs file there.

Upvotes: 3

Views: 5482

Answers (1)

Carl Raymond
Carl Raymond

Reputation: 4479

I just now had the same problem. Look into App_Start\NinjectWebCommon.cs It's got the code to create the kernel and register services, and it's invoked automatically. Change your Global.asax.cs back to the default code (with Application_Start() and no Ninjectery). That got me past the error.

Upvotes: 4

Related Questions