我正在尝试使用 StructureMap 构建 ASP.NET MVC2 控制器,但 ASP.NET 似乎不记得我调用过ControllerBuilder.Current.SetControllerFactory
在我的 Global.asax 文件中。
具体来说,我得到的错误是我的控制器没有无参数构造函数。堆栈跟踪显示我的自定义ControllerFactory
从未被真正执行过。
下面是我对应该告诉 ASP.NET 使用哪个 ControllerFactory 的方法的调用:
Sub Application_Start()
RegisterRoutes(RouteTable.Routes)
ControllerBuilder.Current.SetControllerFactory(GetType(StructureMapControllerFactory))
BootStrapper.RegisterDependencies()
End Sub
这是我收到的例外情况。
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
为什么 ASP.NET 忘记使用哪个 ControllerFactory?