问题描述
以下有关MEF技术的演示应用程序不起作用。 无法构建最简单的可扩展应用程序。我从最简单的控制台应用程序开始,该应用程序将根据指定的参数在屏幕上简单地显示文本。甚至在这里他也没有去找我。在哪里挖?
IDemoInterface.cs
public interface IDemoInretface
{
void Run(int sleep,int count);
}
MEFDataDemo Program.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.IO;
namespace MEFDataDemo
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.Run();
}
public void Run()
{
DoImport();
int count = 1;
foreach (var item in Plugin)
{
item.Value.Run(count * 1000,count * 10);*** This is Error
count++;
}
}
[ImportMany(typeof(IDemoInretface))]
public IEnumerable<Lazy<IDemoInretface>> Plugin { get; set; }
public void DoImport()
{
var catalog = new AggregateCatalog();
var path = Path.Combine(Directory.GetCurrentDirectory(),"Plugins");
catalog.Catalogs.Add(new DirectoryCatalog(path));
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
}
}
Plugin1 Class1.cs
using System;
using System.ComponentModel.Composition;
using System.Threading;
namespace Plugin1
{
[Export(typeof(IDemoInretface))]
internal class Class1 : IDemoInretface
{
public void Run(int sleep,int count)
{
for (int i = 0; i < count; i++)
{
Console.WriteLine("This plugin1 print {0}/{1} in {2}ms",i,count,sleep);
Thread.Sleep(sleep);
}
}
}
}
我在做什么错? 该程序可以编译,但是不读取插件,或者读取但不运行(RUN)方法
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)