1

I'm trying to learn about Dependency Injection in ASP.NET MVC4 using this guide:

http://www.codeproject.com/Articles/412383/Dependency-Injection-in-asp-net-mvc4-and-webapi-us

However I am getting the following exception being thrown when I try and run the application:

An exception of type 'System.IO.FileNotFoundException' occurred in Ninject.dll but was not handled in user code

Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

I am using Visual Studio 2013 Express Edition on Windows 7. Below is my global.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Cars.Domain.Abstract;
using Cars.Domain.Concrete;
using Ninject;
using Ninject.Web.Common;
using Ninject.Web.Mvc;

namespace Cars.WebUI
{
    public class MvcApplication : NinjectHttpApplication
    {
        protected override IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            kernel.Load(Assembly.GetExecutingAssembly());
            kernel.Bind<IModelRepository>().To<EFModelRepository>();
            return kernel;
        }

        protected override void OnApplicationStarted()
        {
            base.OnApplicationStarted();
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
}

1 Answer 1

2

When you install the Nuget package for Ninject.MVC3, it should create a file NinjectWebCommon.cs inside the App_Start folder of your MVC project.

Use that file to load your modules and configure your bindings. As far as I know, you don't need to use this Global.asax code anymore, so don't subclass the NinjectHttpApplication inside it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, the guide I was using is for when you manually download the DLLs, Since I used NuGet it was so much easier than I thought it was!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.