插件架构/依赖注入问题 [英] Plugin Architecture/Dependency Injection Question

查看:229
本文介绍了插件架构/依赖注入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一个架构的插件,但我从来没有与工作。从本质上讲,我的程序支持多种数据库后端,但只有一次。

I'm trying to figure out an architecture for plugins, but I've never worked with that. Essentially, my Program supports multiple database backends, but only one at a time.

我的想法是,现在创建一个新的组件(.DataCore),其中包含我的所有库接口(IFooRepository,IBarRepository)和IDataPlugin接口。然后,插件必须实现所有的接口。

my idea was now to create a new Assembly (".DataCore") that contains all my Repository Interfaces (IFooRepository, IBarRepository) and a IDataPlugin Interface. Then, the Plugins have to implement all those interfaces.

用户指定的app.config文件所需要的程序集的名称。我的计划将随后致电DataCore的大会中的函数,又使用反射来加载所需的组件。使用反射,我再搜索实现IDataPlugin类和调用初始化()函数,它包含了所有的DI绑定Ninject。

The user specifies the Name of the desired Assembly in the app.config file. My Program will then call a function within the DataCore Assembly which in turn uses Reflection to load the desired Assembly. Using reflection, I then search for the Class that implements IDataPlugin and call an Initialize() Function, which contains all the DI Bindings for Ninject.

所以,我的架构是这样的:

So my architecture looks like:

MyProgram =>新DataCoreLoader(字符串的AssemblyName)=> DesiredDataPlugin.Initialize()

MyProgram => new DataCoreLoader(string assemblyName) => DesiredDataPlugin.Initialize()

我只是不知道这是正确的方式,如果我要真的实现这个自己使用反射。我想有现有的框架?我看着M​​EF短暂,但我不知道这是否会帮助吗?

i'm just not sure if that is the right way, and if I should really implement this myself using reflection. I guess there are existing Frameworks? I looked at MEF briefly, but I do not know if that would help?

为什么我要我的插件,至少有一个发现的类的原因是:a)我想查一个ProtocolVersion一些对我的一个程序需要,及时发现过期插件和b)我的配置工具应该提供所有的列表数据插件与一些元数据,比如作者或说明。

The reasons why I want my Plugins to have at least one discoverable class are a) I want to check a ProtocolVersion number against the one my program expects, to detect outdated plugins and b) My Configuration Tool should offer a list of all DataPlugins with some Metadata like Author or Description.

它永远不会需要加载多个数据插件,在同一时间,但我正在寻找的东西,将允许在其他领域(在应用程序中的另一部分,我想使用订阅插件活动我的应用程序发出)。

It will never be needed to load more than one Data plugin at the same time, but I'm looking for something that would allow that in other areas (In another part of the application, I want to use Plugins that subscribe to Events my Application emits).

推荐答案

这是一个合理的方法来实现插件。

That's a reasonable way to implement plugins.

这篇关于插件架构/依赖注入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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