设置ASP.NET MVC的ControllerFactory没有效果 [英] Setting ASP.NET MVC ControllerFactory has no effect

查看:318
本文介绍了设置ASP.NET MVC的ControllerFactory没有效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有我的ASP.NET MVC2控制器使用StructureMap但ASP.NET似乎不记得我叫建 ControllerBuilder.Current.SetControllerFactory 我在Global.asax文件。

I'm trying to have my ASP.NET MVC2 controllers built using StructureMap but ASP.NET doesn't seem to remember that I've called ControllerBuilder.Current.SetControllerFactory in my Global.asax file.

具体来说,我让我的控制器无参数的构造函数的错误。堆栈跟踪显示我的自定义的ControllerFactory 从来没有真正执行。

Specifically I get the error that my controller has no parameterless constructor. The stack trace reveals that my custom ControllerFactory was never actually executed.

下面是我应该告诉ASP.NET使用哪个的ControllerFactory方法调用:

Here is my call to the method that should tell ASP.NET which ControllerFactory to use:

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?

Why is ASP.NET forgetting which ControllerFactory to use?

推荐答案

如何您StructureMapControllerFactory界定?它有一个默认的构造函数?

How is your StructureMapControllerFactory defined? Does it have a default constructor?

如果没有,请尝试使用SetControllerFactory方法的第二个重载:

If not, try using that second overload of the SetControllerFactory method:

// First create the controllerFactory instance...

ControllerBuilder.Current.SetControllerFactory(controllerFactory);

这篇关于设置ASP.NET MVC的ControllerFactory没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆