公共服务注册 [英] Common Service Registry

查看:154
本文介绍了公共服务注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在很长一段时间,现在我们已经足够幸运,有公共服务定位​​器(CSL)从未知来源解析服务。然而,从未有过的在第一时间注册这些服务的任何容器无关的解决方案。我们一直面临着不得不对夫妇我们的作文code到特定的IoC容器的问题,此外,致力于用我们整个应用程序的容器。

For a long time now we've been fortunate enough to have the Common Service Locator (CSL) to resolve services from an unknown source. However, there has never been any container-agnostic solution for registering these services in the first place. We've always been faced with the problem of having to couple our composition code to a particular IoC container, and furthermore, be committed to using that container throughout our entire application.

我觉得我可能试图实现不可能在这里,但没有任何人有关于如何实现任何想法公共服务注册(CSR)?

I feel I may be trying to achieve the impossible here, but does anyone have any ideas on how to achieve a Common Service Registry (CSR)?

我最初的想法是使用MEF解决各种 IContainerIntegrator S(一个班每个容器的技术),从而使用MEF解决各种 IXXXContainerBinding S(一个接口的每一种技术)。然后,用户可以开发各地的集装箱绑定应用程序,以及刚落,他们的绑定到BIN目录中,实现了插件架构。如果他们想用一个新的容器技术,那么他们就只需要开发一个新的 IContainerIntegrator 类和相应的 IXXXContainerBinding ,他们将然后用自己写的绑定。在应用程序启动时,CSR使用 ServiceLocatorAggregator 类汇集了所有的容器实例成一个单一的CSL。

My original idea was to use MEF to resolve various IContainerIntegrators (one class for each container technology), which in turn use MEF to resolve various IXXXContainerBindings (one interface for each technology). Users could then develop applications around container bindings, and just drop their bindings into the BIN directory to achieve a plugin architecture. If they wanted to use a new container technology, then they would just have to develop a new IContainerIntegrator class and accompanying IXXXContainerBinding, which they would then use to write their own bindings. At application startup the CSR aggregates all of the container instances into a single CSL using a ServiceLocatorAggregator class.

我有这个工作,但我面临着以下问题:

I have got this working, but am faced with the following problems:

  • 任何结合,这使得调用电流(不完全的)容器是不稳定的,由于previous登记的可能的被随后的绑定重写。这包括需要解决的对象予以登记的决定(即结合这一点,如果这是present')绑定。
  • 在两个绑定可能存在其中公开相同的服务集。但是,我们要'隔行'这些注册。例如。 我要服务A和C的结合X和服务B和D的结合Y'。
  • 集装箱从自己想办法解决服务时,自动布线要求的服务依存关系。例如。 container.Bind<本>。为<也就是说>()',会自动注入与'集装箱'解决服务的实现 - 而不是从聚合服务定位器
  • Any binding which makes calls to the current (incomplete) container is unstable, since the previous registrations may be overridden by subsequent bindings. This includes bindings which need to resolve objects to make registration decisions (i.e. 'bind this if that is present').
  • Two bindings may exist which expose the same set of services. However, we want to 'interlace' these registrations. E.g. 'I want services A and C from binding X, and service B and D from binding Y'.
  • Containers resolve services from themselves when auto-wiring dependencies of requested services. E.g. 'container.Bind<This>.To<That>()' will automatically inject the implementation with services resolved from 'container' - not from the aggregated service locator.

请喊我,如果我这里完全忽略了一点,但不是这个的的解耦的依赖关系管理解决方案?那岂不是很好吗?我即将踏上大企业项目,一个插件架构。我不想承诺一个特定的IoC容器。

Please shout at me if I've completely missed the point here, but isn't this the most decoupled solution for dependency management? Wouldn't it be nice? I'm about to embark on a big enterprise project with a plugin architecture. I don't want to commit to a particular IoC container.

(PS这个问题是关于支持发现容器不可知的组合,请不要进入在SL VS DI的辩论。SL采用的是成分,这就是为什么我提到它了在这里)。

(p.s. This question is about container-agnostic composition which supports discovery. Please do not enter a debate on SL vs DI. SL is used in composition, which is why I've referenced it so much here).

推荐答案

最解耦(和最好)解决方案可以实现是实现松耦合是通过的原则和模式,而不是最好的实现特别的技术。

The most decoupled (and the best) solution you can achieve is to realize that loose coupling is best achieved through principles and patterns instead of particular technologies.

使用构造器注入整个应用程序。该将确保没有你的应用层需要引用任何容器都。然后构成整个应用图形中的应用的的根。

Use Constructor Injection throughout your application. The ensures that none of your application layers need reference any container at all. Then compose the entire application graph in the root of the application.

您不要的需要的使用DI容器这一点,但如果你选择使用DI容器,你必须找出它的成分根 。这意味着,如果你以后决定迁移到不同的容器,​​你只需要改变构图根。然而,穷人的DI 也是一种选择。

You don't need to use a DI Container for this, but if you choose to use a DI Container, you must isolate it to the Composition Root. This means that if you later decide to migrate to a different container, you only need to change the Composition Root. However, Poor Man's DI is also an option.

这篇关于公共服务注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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