MVCTurbine 中 Application_Start 的替代品是什么?

发布于 2024-09-10 01:06:04 字数 520 浏览 2 评论 0原文

显然,这个方法不再被调用......在那里我们有用于配置 AutoMapper 和设置模型绑定器的代码。

我知道有一种“新”方法来执行模型绑定程序,但是......在我实现该方法之前,我是否仍然可以使用“旧方法”?

具体来说,我的旧 Application_Start() 方法还剩下两行,我无法正常工作:

        AutoMapperConfiguration.Configure();

        ModelBinders.Binders[typeof (ModuleEditModel)] = new DerivedModelBinder();

我尝试简单地将它们弹出到构造函数中,就在调用之后: ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator());

这运行了,但是..似乎不知何故没有生效。在运行应用程序时,很明显 AutoMapper 不满意,没有它应该有的映射,等等。

Apparently, this method no longer gets called... In there we have code for configuring AutoMapper, and for setting model binders.

I know there is a "new" way to do model binders, but... shouldn't I still be able to do it "the old way" until I get that implemented?

Specifically, I have two lines left from my old Application_Start() method that I have been unable to get working:

        AutoMapperConfiguration.Configure();

        ModelBinders.Binders[typeof (ModuleEditModel)] = new DerivedModelBinder();

I've tried simply popping those into the constructor, right after the call to: ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator());

And that runs, but.. it seems somehow not to take effect. In running the application it is clear that AutoMapper isn't happy, doesn't have the mappings it is supposed to have, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

噩梦成真你也成魔 2024-09-17 01:06:04

我在 CodePlex 上的涡轮机讨论区上回答了这个问题。这是用于进行您要求的更改的来源

public class MvcApplication : TurbineApplication {
    static MvcApplication() {
        // Register the IoC that you want Mvc Turbine to use!
        // Everything else is wired automatically

        // For now, let's use the Unity IoC
        ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
    }

    public override void Startup(){
         // Gets called when the application starts up
         // and before all the stuff that Turbine wires up
    }

    public override void Shutdown() {
         // Gets called when the application shuts down
         // and before any cleanup is done by Turbine
    }
}

希望这有帮助!

I answered this question out on the Turbine Discussion board on CodePlex. Here's the source for making the changes you ask for:

public class MvcApplication : TurbineApplication {
    static MvcApplication() {
        // Register the IoC that you want Mvc Turbine to use!
        // Everything else is wired automatically

        // For now, let's use the Unity IoC
        ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
    }

    public override void Startup(){
         // Gets called when the application starts up
         // and before all the stuff that Turbine wires up
    }

    public override void Shutdown() {
         // Gets called when the application shuts down
         // and before any cleanup is done by Turbine
    }
}

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文