【发布时间】:2014-01-28 14:46:40
【问题描述】:
我正在尝试使用本指南了解 ASP.NET MVC4 中的依赖注入:
http://www.codeproject.com/Articles/412383/Dependency-Injection-in-asp-net-mvc4-and-webapi-us
但是,当我尝试运行应用程序时抛出以下异常:
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.
我在 Windows 7 上使用 Visual Studio 2013 Express Edition。下面是我的 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);
}
}
}
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4 ninject