Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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# 指定类型的CompositionBatch.AddExportedValue_C#_Inversion Of Control_Mef - Fatal编程技术网

C# 指定类型的CompositionBatch.AddExportedValue

C# 指定类型的CompositionBatch.AddExportedValue,c#,inversion-of-control,mef,C#,Inversion Of Control,Mef,我按如下方式设置容器: .... CompositionContainer container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(_dataClient); batch.AddExportedValue(_orderClient); batch.AddExportedValue(container); conta

我按如下方式设置容器:

....
CompositionContainer container = new CompositionContainer(catalog);
CompositionBatch batch = new CompositionBatch();

batch.AddExportedValue(_dataClient);
batch.AddExportedValue(_orderClient);
batch.AddExportedValue(container);
container.Compose(batch);
\u dataClient
\u orderClient
位于不同的程序集中,我无法触摸它们。但是,它们分别实现了
IDataFeed
IOrderFeed
(但是它们的类型分别是
DataClient
OrderClient
)。稍后,我希望它们出现在构造函数中:

[ImportingConstructor]
public ShellViewModel(IShellView view, IDataFeed dataFeed, IOrderFeed orderFeed)
...
但这会引发一个
importCardinalismatchException
。但是,如果我将构造函数更改为此,它将起作用:

[ImportingConstructor]
public ShellViewModel(IShellView view, DataClient dataFeed, OrderClient orderFeed)
...
我尝试了这一点,但提出了相同的例外:

...
batch.AddExportedValue(typeof(IDataFeed).FullName, _dataClient);
batch.AddExportedValue(typeof(IOrderFeed).FullName, _orderClient);
...
如何将
\u dataClient
\u orderClient
添加到容器中,就像我这样做了一样:

[Export(typeof(IDataFeed))]
public class DataClient : IDataFeed
{
    ...
我该怎么做?理想情况下是这样的:

batch.AddExportedValue(typeof(IDataFeed), _dataClient);

修复很容易。不知道我怎么会错过

batch.AddExportedValue((IDataFeed)_dataClient);