从.NET MVC 1迁移到MVC 2 RC

时间:2010-01-05 08:42:32

标签: asp.net-mvc-2 castle-windsor

我已将MVC1项目迁移到MVC2 RC,现在该站点根本不起作用。我收到错误“找不到入口点。”

我在this link

之后迁移了该项目

我正在使用Castle Windsor作为DI。

以下是global.asax.cs

的一部分
public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", "{controller}/{action}/{id}", new { controller = "Main", action = "Index", id = "" });
    }

    protected void Application_Start()
    {
        log4net.Config.XmlConfigurator.Configure();
        InitializeServiceLocator();
        //RouteConfigurator.RegisterRoutesTo(RouteTable.Routes);
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        Bootstrapper.BootStrap();
    }

    /// <summary>
    /// If you need to communicate to multiple databases, you'd add a line to this method to
    /// initialize the other database as well.
    /// </summary>
    private void InitializeNHibernateSession()
    {
        var cfg =
            NHibernateSession.Init(
                webSessionStorage,
                new string[] { Server.MapPath("~/bin/Edi.Advance.EPortfolio.Data.dll") },
                new AutoPersistenceModelGenerator().Generate(),
                Server.MapPath("~/hibernate.cfg.xml")).AddAssembly(typeof(ISoftDeletable).Assembly).AddAssembly(
                typeof(Action).Assembly);

        //cfg.SetListener(ListenerType.Delete, new AdvanceDeleteEventListener(IoC.Resolve<ISecurityContextService>()));
        //cfg.SetListener(ListenerType.SaveUpdate, new AdvanceSaveUpdateEventListener(IoC.Resolve<ISecurityContextService>()));
    }

    /// <summary>
    /// Instantiate the container and add all Controllers that derive from 
    /// WindsorController to the container.  Also associate the Controller 
    /// with the WindsorContainer ControllerFactory.
    /// </summary>
    protected virtual void InitializeServiceLocator()
    {
       // AddComponentsToIoC();
        var container = new WindsorContainer();

        ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
        container.RegisterControllers(typeof(MainController));

        ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

    }

MainController非常简单,Index动作只返回“Hello World from MVC2”字符串。 (没有对此行动的看法)。

有趣的是,如果我注释掉这一行:

ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

MainController工作正常,但是由于其他更复杂的控制器无效,因此没有无参数构造函数。

所以它接缝是WindsorControllerFactory的错误。

有什么想法吗? 感谢

2 个答案:

答案 0 :(得分:4)

使用:
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext,Type controllerType)

Insted of: protected override IController GetControllerInstance(Type controllerType)

答案 1 :(得分:3)

使用: protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext,Type controllerType)

Insted of: protected override IController GetControllerInstance(Type controllerType)