MEF(受控可扩展性框架),目录目录和结构思想(最佳实践) [英] MEF (Managed Extensibility Framework), DirectoryCatalogues and structural thoughts (best practices)

查看:114
本文介绍了MEF(受控可扩展性框架),目录目录和结构思想(最佳实践)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已经和MEF待了很长时间了,对此感到非常满意.
从现在开始,我使用DirectoryCatalog按照特定的命名约定加载dll(所有dll/exe都位于同一文件夹中).

现在,我有机会以不同的方式构造相同的东西,因为过去我不知何故将所有内容放入单个文件夹中.

我考虑过要为新项目使用以下结构(我将[xxx]用于文件夹):

[MainApplication]
... MainApplication.exe
... [lib]
............ ContractsLibrary.dll
... [插件]
...... [HelloWorldPlugin]
......... HelloWorld.exe


MainApplication.exe包含PluginManager,它会在[plugins]文件夹上进行迭代,并为每个子文件夹创建DirectoryCatalog,然后创建相关的CompositionContainer.
它引用ContractsLibrary.dll来了解插件必须导出的合同.

HelloWorld.exe还需要引用ContractLibrary.dll,以了解它必须导出的合同.

在开发过程中,两者都引用位于[lib]文件夹中的ContractsLibrary.dll,并将本地副本设置为false.

实际上,由于在编写HelloWorld.exe(与ContractsLibrary.dll相关)期间引发了FileNotFOundException,因此导入无法正常工作.
我通过在MainApplication.exe中实现AssemblyResolve来解决此问题,该组件将使用[lib]文件夹中的ContractsLibrary.dll.

所以这听起来很麻烦,不是吗?

无论如何,在尝试了一下之后,我现在正在寻找一种更专业的方法来构建应用程序,这应该能够导入共享相同dll的插件([lib]文件夹中的插件). >
构建满足上述需求的项目的好方法是什么?

如果您对此问题有任何疑问,请随时提出,我会尽力澄清一下...

另外,如果您对与本主题相关的内容有很好的阅读,请将其放入,我将进行深入研究.

感谢您的任何投入,
最好的问候
Andy

Hi all,
I am dealing with MEF for quite a while now and was quite pleased with it.
Since now I used a DirectoryCatalog that loaded dll''s following a specific naming convention (all dll''s/exe''s etc in the same folder).

Now I get the chance to structure something equal in a different way, because I somehow felt dirty in the past putting everything into a single folder.

I thought about having the following structure for the new project (I use [xxx] for folders):

[MainApplication]
...MainApplication.exe
...[lib]
......ContractsLibrary.dll
...[plugins]
......[HelloWorldPlugin]
.........HelloWorld.exe


MainApplication.exe contains the PluginManager, which iterates over the [plugins] folder and creates a DirectoryCatalog for each subfolder and then creates the related CompositionContainer.
It references the ContractsLibrary.dll in order to know about the contract that a plugin has to export.

HelloWorld.exe also needs to reference the ContractLibrary.dll in order to know about the contract it has to export.

During development both reference the ContractsLibrary.dll located in the [lib] folder having copy local set to false.

Actually the import doesn''t work due to a FileNotFOundException that is thrown during composition of HelloWorld.exe (related to the ContractsLibrary.dll).
I solved this issue by implementing AssemblyResolve in MainApplication.exe that will use the ContractsLibrary.dll from the [lib] folder.

So this already sounds problematic, doesn''t it?

Anyway, after having given this a try I am now searching for a more professional way to structure an application tha should be able to import plugins that share the same dll''s (the ones in the [lib] folder).

What is a good way to structure a project fulfilling above mentioned needs?

If you have any questions regarding this question do not hesitate to ask and I''ll try to clarify it...

Also, if you have a good read related to the topic at hand, just drop it in and I''ll dig through it.

Any input is kindly appreciated,
best regards
Andy

推荐答案

我已经将MEF用于大型医疗系统已有一段时间了.我们还为插件使用了单独的文件夹.实际上,我们也有多个文件夹,其中包含各种插件.

我们与您的设置唯一的区别是合同DLL位于我们的主文件夹中,而不是lib文件夹中.我不介意合约DLL位于主文件夹级别,因为它是直接针对它进行编译的.这也使我不必更改AssemblyResolve.如果您的设置偏离了基础,那么我的也是.但是至少您现在知道,另一个开发人员使用了与您几乎相同的想法(没有lib文件夹).
I have used MEF for a large medical system for sometime now. We also use a separate folder for the plugins. Actually we have multiple folders as well that various plugins are in.

The only difference that we have from your setup is that the contract DLL is in our main folder, not a lib folder. I did not mind the contract DLL being at the main folder level because it is something that it directly compiles against. This also saved me from having to change the AssemblyResolve as well. If your setup is way off-base then mine is as well. But at least you now know that another developer used pretty much the same ideas that you did (without the lib folder).


这篇关于MEF(受控可扩展性框架),目录目录和结构思想(最佳实践)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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