Events MEF-双向进出口

Events MEF-双向进出口,events,import,export,mef,aggregation,Events,Import,Export,Mef,Aggregation,我使用MEF是为了在我的项目中执行插件代码。 1.我正在加载我的dll源: public void AssembleComponents() { try { //Creating an instance of aggregate catalog. It aggregates other catalogs var aggregateCatalog = new AggregateCatalog();

我使用MEF是为了在我的项目中执行插件代码。
1.我正在加载我的dll源:

   public void AssembleComponents()
    {
        try
        {
            //Creating an instance of aggregate catalog. It aggregates other catalogs
            var aggregateCatalog = new AggregateCatalog();

            //Build the directory path where the parts will be available
            var directoryPath =
                string.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)
                            .Split('\\').Reverse().Skip(4).Reverse().Aggregate((a, b) => a + "\\" + b)
                            , "\\", "ExportComponents\\Components");


            string localPath = new Uri(directoryPath).LocalPath;
            //Load parts from the available dlls in the specified path using the directory catalog
            var directoryCatalog = new DirectoryCatalog(localPath, "*.dll");

            //Load parts from the current assembly if available
            var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            //Add to the aggregate catalog
            aggregateCatalog.Catalogs.Add(directoryCatalog);
            aggregateCatalog.Catalogs.Add(asmCatalog);

            //Crete the composition container
            var container = new CompositionContainer(aggregateCatalog);

            // Composable parts are created here i.e. the Import and Export components assembles here
            container.ComposeParts(this);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
  • 我正在检查我的插件并执行“验证”方法:

    公共列表验证(字符串操作类型)
    {
    列表res=null;
    foreach(ChekcsPlugins中的System.Lazy插件)
    {
    if(plugin.Metadata.DisplayName==operationType)
    {
    res=plugin.Value.Validate();
    打破
    }
    }
    返回res;
    }
    
  • 我知道在“验证”完成后如何导出返回值,但我需要的是在方法执行期间的运行时返回值。
    有可能吗?

    您能否详细说明“在方法执行期间的运行时返回值”的含义?我不确定你到底在问什么。验证方法是在不同的DLL上实现的。正如您所看到的,它将值返回给“res”变量。我希望在验证执行期间返回值(例如字符串),而不是在最后返回1个值。
    public List<string> Validate(string operationType)
    {
        List<string> res = null;
        foreach (System.Lazy<IValidationRules, IPluginMetadata> plugin in ChekcsPlugins)
        {
            if (plugin.Metadata.DisplayName == operationType)
            {
                res = plugin.Value.Validate();
                break;
            }
        }
        return res;
    }