• 【WCSF】DynamicMethod 的类型所有者无效解决方案


    We came accross this problem in our application and we came up with a solution.

    In our case, the user control had its own presenter which also used interacted with a controller defined in the same module as the presenter. The issue was that when controllers are registered in the module Load method, they are registered only in the module's container - not globally. This means that the controller can only be instantiated if the DI container being used is from the same module.

    To overcome the problem, we simply changed the module initializer's Load method to register the controller on the parent container (same as for global services).

    I.e. change the following code...
    --------------------------------------

    public override void Load(CompositionContainer container)
    {
    base.Load(container);

    AddGlobalServices(container.Parent.Services);
    AddModuleServices(container.Services);

    ...

    container.RegisterTypeMapping<IAdministrationController, AdministrationController>();
    }

    --------------------------------------



    ... into this:
    --------------------------------------

    public override void Load(CompositionContainer container)
    {
    base.Load(container);

    AddGlobalServices(container.Parent.Services);
    AddModuleServices(container.Services);

    ...

    // Register the controller on container.Parent to make it available for DI globally.
    container.Parent.RegisterTypeMapping<IAdministrationController, AdministrationController>();
    }

    --------------------------------------

    刚刚遇到这个问题,解决了留个记号日后待用。

  • 相关阅读:
    bzoj 2599
    bzoj 3697
    poj 1741
    bzoj 2741
    bzoj 5495
    bzoj 3261
    网络流24题——骑士共存问题 luogu 3355
    网络流24题——数字梯形问题 luogu 4013
    bzoj 3998
    网络流24题——魔术球问题 luogu 2765
  • 原文地址:https://www.cnblogs.com/ahjesus/p/2230855.html
Copyright © 2020-2023  润新知