使用 MEF 从 X 个文件夹导入零件

发布于 2024-07-21 07:54:48 字数 337 浏览 7 评论 0原文

我有许多文件夹,其中都包含应导入的 MEF 部件。 找到所有部分以迭代文件夹并创建 MEF 聚合目录对象的最简单方法是?

我需要根据从中读取的文件夹将部件放置在应用程序中的不同位置。 因此,文件夹“Test1Parts”中的部件应放置在应用程序的“Test1”部分下。 我是否有可用的文件夹名称,或者通过聚合目录导入后它们看起来都一样吗?

我有通用部件,因此我无法真正在每个部件上添加属性并重新编译,只是为了让它们显示在应用程序中的不同部分。

另一种方法(如果无法通过文件夹结构控制)当然是使用我在导入之前阅读的配置文件,告诉哪些部分应该放在哪里。

最好的方法是什么?

I have a number of folders that all contains MEF parts that should be imported. Is the easiest way to find all the parts to iterate over the folders and create a MEF Aggregating Catalog object?

I need to place the parts in different places in the application based on the folder it was read from. So parts from folder "Test1Parts" should be places under the "Test1" section of the application. Do I have the folder name available somehow or will they all look the same once imported via the Aggregating Catalog?

I have generic parts so I can't really put a attribute on each of them an recompile just to have them show up on a different section in the application.

Another way (if it can't be controlled via the folder structure) is f course to use a configuration file that I read before importing telling what part should go where.

What would be the best approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我最亲爱的 2024-07-28 07:54:49

我认为最好的方法是为每个文件夹提供一个单独的容器,并为该文件夹中的各个部分提供相应的 DirectoryCatalog。 如果存在需要全局的部件,则您可以拥有包含这些部件的父目录,并为每个目录创建子目录。

I think the best way to do this is to have a separate container for each folder along with a corresponding DirectoryCatalog for the parts in that folder. If there are parts that need to be global, then you can have a parent catalog that contains those parts and have child catalogs for each directory.

贪恋 2024-07-28 07:54:49

我不是 100% 清楚您想要做什么,但我建议为应用程序的每个“部分”使用一个聚合目录。 然后,您将根据每个部分的零件目录对每个部分执行 Compose。 每个目录仅包含相关目录中的部分(您还可以将一些通用目录加载到两个目录中)。 这有任何意义吗?

I'm not 100% clear on what you're trying to do, but I suggest using one Aggregating Catalog for each "section" of your application. Then you'd execute a Compose on each section, based on the part catalog for that section. Each catalog would only include parts from the relevant directories (you could also have some common directories that get loaded into both catalogs). Does that make any sense?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文