小编Tra*_*raw的帖子

Ninject + MVC3没有注入控制器

我已经使用了NuGet Ninject MVC3扩展,并且根据请求无法将其注入控制器.它似乎没有绑定,因为MVC正在寻找无参数的构造函数.这是堆栈跟踪:

    [MissingMethodException: No parameterless constructor defined for this object.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
       System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
       System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67

    [InvalidOperationException: An error occurred when trying to create a controller of type 'MyApp.Presentation.Controllers.SearchController'. Make sure that the controller has a parameterless public constructor.]
       System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182
       System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net binding ninject asp.net-mvc-3

14
推荐指数
2
解决办法
5956
查看次数

标签 统计

asp.net ×1

asp.net-mvc-3 ×1

binding ×1

c# ×1

ninject ×1