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

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

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

转载于:https://www.cnblogs.com/ahjesus/archive/2011/10/31/2230855.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值