我試圖讓我的ASP.NET MVC2控制器使用StructureMap構建,但ASP.NET似乎沒有記得我在Global.asax文件中調用了ControllerBuilder.Current.SetControllerFactory
。設置ASP.NET MVC ControllerFactory沒有任何作用
特別是我得到錯誤,我的控制器沒有無參數的構造函數。堆棧跟蹤顯示我的自定義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?
您好。我設法通過創建一個新的Visual Studio項目並將代碼從我的其他項目複製到它來解決此問題。一切都在那之後工作。 代碼本身沒有改變。 – 2011-02-17 09:39:57