【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>();
}

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

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

你可能感兴趣的:(dynamic)