MEF问题 [英] MEF problem

查看:101
本文介绍了MEF问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种情况.有代码段:

I have this situation. There is code snippet:

interface ICorePlugin
{
	void Initialize();
}

interface IAutomaticPlugin
{
	void InitializeAutomatic();
}

[Export(ICorePlugin)]
class A:ICorePlugin

{
	...importmany automatic plugins...
	
	ctor
	{
		Loader.LoadPlugins(this, typeof(IAutomaticPlugin));
	}
	
	public Initialize()
	{
		foreach(autoplugin in plugins)
		{
			autoplugin.InitializeAutomatic();
		}
	}	
}

[Export(IAutomaticPlugin)]
class B:IAutomaticPlugin
{	
	ctor
	{		
	}
	
	public InitializeAutomatic()...
}

class Loader
{
	public static LoadPlugins(object pluginHost, Type pluginInterface)...
}


class Manager
{
	importmany ICorePlugin...
	
	ctor Manager
	{
		LoadPlugin(this, typeof(ICorePlugin));
	}
	
	public void Start()
	{
		foreach(coreplugin in plugins)
		{
			coreplugin.Initialize();
		}
	}
}

在Loader类中,LoadPlugins方法在目录中浏览并找到正确的程序集,然后将其添加到聚合目录中,最后从CompositionContainer添加到ComposeParts中.我检查了调试器,发现所有符合条件的程序集.通话开始时 核心插件的方法中没有动作插件,从不调用InitializeAutomatic,并且没有将动作插件加载到核心插件中.我检查目录一切正常.

In Loader class, LoadPlugins method surf throug directory and find right assembly, then add it to aggregate catalog and at the end ComposeParts from CompositionContainer. I check through debuger and I found all assembly that meet condition. When call start method for core plugin there is no action plugin in it, InitializeAutomatic is never called, there is no action plugin loaded into core plugin. I check directory everything is ok.

我做错了什么?


推荐答案

在调用Compose之前是否将聚合目录添加到组合容器?

do you add the aggregate catalog to the composition container before you call Compose?


这篇关于MEF问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆