asp mvc 2结构图在部署时无法正常工作

时间:2010-03-01 18:53:42

标签: c# .net asp.net-mvc iis structuremap

我在我的asp mvc网站上使用结构图,我刚刚尝试将其部署到II6上。

基本依赖结构非常典型:

    public ControlMController(IControlMService controlMservice)
    {
        this._controlMservice = controlMservice;
    }

    ...

    public ControlMService(IControlMRepository repo)
    {
        this._repo = repo;
    }

    ...

    public SQLControlMRepository (CTRLMDataContext dataContext)
    {
        _db = dataContext;
    }

我的structureMap Registry就像这样

        For<IControlMService>().Use<ControlMService>();
        For<IControlMRepository>().Use<SQLControlMRepository>();
        //For<IControlMRepository>().Use<TestControlMRepository>();
        SelectConstructor<CTRLMDataContext>(() => new CTRLMDataContext());
        For<CTRLMDataContext>().LifecycleIs(new HybridLifecycle()).Use<CTRLMDataContext>();

我的控制器工厂看起来像这样:

public class ControllerFactory : DefaultControllerFactory 
{
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        try
        {
            if (controllerType == null) return base.GetControllerInstance(requestContext,controllerType);
            return ObjectFactory.GetInstance(controllerType) as IController;
        }
        catch
        {
            System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
            return null;
        }
    }
}

这在开发服务器上100%有效,但在我部署到服务器上的IIS 6时无效。

具有所有依赖项的ControlMController返回以下异常:

[InvalidOperationException: The IControllerFactory 'SupportTool.web.Controllers.ControllerFactory' did not return a controller for the name 'ControlM'.]
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +304
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

所有其他具有0依赖关系的控制器在服务器上运行良好,因此structuremap的安装必须有点工作,而不是完全:/

1 个答案:

答案 0 :(得分:3)

自我回答!

问题是我的datacontext的构造函数正在抛出,因为数据库域名不是完全限定的,而我的电脑解析了它,服务器却没有。

包含信息的内部异常未显示在错误页面上!

:)