插件配置 [英] Plugin Configuration
问题描述
嗨。
我的情况是我有多个插件具有相同的导出。我需要将选定的插件存储到配置中并在需要时立即安装。
有什么标准的方法我可以去吗?
b $ b我可以在需要时发布一些代码示例。
Hi.
I have the scenario where i have mulitple plugins that are of the same export. I need to store the selected plugin to a configuration and instanate it when needed.
Is there any standart way that i can go?
I can post some code examples if needed.
推荐答案
你应该把所有这些都放在一个属性中:
You should get all of them in a property:
[ImportMany(AllowRecomposition = true)]
public Lazy<InterfaceX, IInterfaceXMetadata>[] XXX {get; set;}
如果您使用 Lazy 关键字,请注意tath,并且需要使用它才能实例化。
Note tath if you use the Lazy keyword they aren´t instantiate until you need to use it.
然后通过IInterfaceXMetadata中定义的属性的concret值查询XXX数组过滤,以选择正确的插件(您可以使用Linq)并获取具有属性Value的对象实例。
Then query the XXX array filtering by the concret value of the property defined in IInterfaceXMetadata to select the correct plug-in (you can use Linq) and get the instance of the object with the property Value.
这篇关于插件配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!