【发布时间】:2011-03-02 02:17:13
【问题描述】:
如果这个问题已经被问了 100 次,我很抱歉,但我真的很难让它发挥作用。
假设我有三个项目。
- Core.dll
- 具有通用接口
- Shell.exe
- 加载程序集文件夹中的所有模块。
- 参考 Core.dll
- ModuleA.dll
- 导出名称、模块版本。
- 参考 Core.dll
Shell.exe 有一个 [Export],其中包含我需要注入到所有加载的模块中的第三方应用程序的单个实例。
到目前为止,我在 Shell.exe 中的代码是:
static void Main(string[] args)
{
ThirdPartyApp map = new ThirdPartyApp();
var ad = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var dircatalog = new DirectoryCatalog(".");
var a = new AggregateCatalog(dircatalog, ad);
// Not to sure what to do here.
}
class Test
{
[Export(typeof(ThirdPartyApp))]
public ThirdPartyApp Instance { get; set; }
[Import(typeof(IModule))]
public IModule Module { get; set; }
}
我需要创建一个 Test 实例,并从 Main 方法加载 Instance 和 map,然后从执行目录中的 ModuleA.dll 加载模块,然后 [Import] Instance 到加载模块。
在ModuleA我有一个这样的课程:
[Export(IModule)]
class Module : IModule
{
[Import(ThirdPartyApp)]
public ThirdPartyApp Instance {get;set;}
}
我知道我已经完成了一半我只是不知道如何将它们放在一起,主要是使用来自Main 的map 实例加载测试。
谁能帮帮我。
【问题讨论】:
标签: c# ioc-container mef