Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用“从第三方库注入互操作对象”;Autofac";_C#_Oop_Interface_Com_Autofac - Fatal编程技术网

C# 如何使用“从第三方库注入互操作对象”;Autofac";

C# 如何使用“从第三方库注入互操作对象”;Autofac";,c#,oop,interface,com,autofac,C#,Oop,Interface,Com,Autofac,第三方软件提供了名为ProxyGW 这是他们的接口代码 public interface ProxyGW : IProxyGW10, _ProxyGWEvents_Event { } 这里是接口\u ProxyGWEvents\u事件 public interface _ProxyGWEvents_Event { event _ProxyGWEvents_onConnectSucceededEventHandler onConnectSucceeded; } 这里是IProxyGW1

第三方软件提供了名为
ProxyGW

这是他们的接口代码

public interface ProxyGW : IProxyGW10, _ProxyGWEvents_Event
{
}
这里是接口
\u ProxyGWEvents\u事件

public interface _ProxyGWEvents_Event
{
    event _ProxyGWEvents_onConnectSucceededEventHandler onConnectSucceeded;
}
这里是
IProxyGW10
接口,接着是8,7,6…接口

public interface IProxyGW10 : IProxyGW9
{}
我正在使用
Autofac
来获得依赖注入能力。我已经编写了class
ProxyGWModule
来注册组件

using Autofac;
using ProxyGWLib;

public class ProxyGWModule: Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(ProxyGW);// I get error here
    }
}
错误

“ProxyGW”是一种类型,在给定的上下文ProxyGWModule.cs中无效

如果我这样做,错误就会发生

 ProxyGW proxygw = new ProxyGW();
 builder.RegisterInstance(proxygw).As<IProxyGW10>(); //which interface shall be part of
错误

无法嵌入互操作类型“ProxyGWClass”。改用适用的接口。ProxyGWModule.cs

根类如下所示。IProxyGW9、IProxyGW8…是不同的版本。显然,我们只使用其中一种

 public class ProxyGWClass : IProxyGW10, ProxyGW, _ProxyGWEvents_Event, IProxyGW9, IProxyGW8, IProxyGW7, IProxyGW6, IProxyGW5, IProxyGW4, IProxyGW3, IProxyGW2 {}
因此,下面没有显示任何错误

 ProxyGW proxygw = new ProxyGW();
 builder.RegisterInstance(proxygw).As<IProxyGW9>().As<_ProxyGWEvents_Event>();
ProxyGW ProxyGW=new ProxyGW();
builder.RegisterInstance(proxygw).As().As();

ProxyGW是一个接口。您需要一个实现该接口的类。ProxyGWClass-这就是该类-我收到此错误-无法嵌入互操作类型“ProxyGWClass”。改用适用的接口。ProxyGWModule.csOh,这是一个COM接口。。。这需要Hans Passant。
builder.RegisterInstance(proxygw).As().As()是的,它是COM接口Proxy GW是一个接口。您需要一个实现该接口的类。ProxyGWClass-这就是该类-我收到此错误-无法嵌入互操作类型“ProxyGWClass”。改用适用的接口。ProxyGWModule.csOh,这是一个COM接口。。。这需要Hans Passant。
builder.RegisterInstance(proxygw).As().As()是,这是COM接口
 ProxyGW proxygw = new ProxyGW();
 builder.RegisterInstance(proxygw).As<IProxyGW9>().As<_ProxyGWEvents_Event>();