我正在尝试使用 Autofac 注册跨 AppDomain 代理。
代理表示的具体类型实现接口(interface) IServiceHost。因此,代理也应该允许使用该接口(interface)调用代理。
我尝试通过以下方式向 Autofac 注册代理:
void Initialize(IServiceHost host)
{
Host = host;
var builder = new ContainerBuilder();
builder.RegisterInstance(host)
.As<IServiceHost>()
.SingleInstance();
Scope = builder.Build();
}
但是,在 builder.Build()
调用中,我得到:
ArgumentException
The type 'System.MarshalByRefObject' is not assignable to service 'Treadmarks.Core.ServiceBase.IServiceHost'.
但是,host
是绝对 IServiceHost
,因为它不是 null 并且它来自强类型方法参数。
谁能解释一下如何正确注册代理?
最佳答案
您应该能够将 lambda 与 .Register()
方法(而不是 .RegisterInstance()
)结合使用来解决这个问题。
关于c# - Autofac 和跨 AppDomain 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9584873/