OSGi应用设计 - 我滥用服务框架吗? [英] OSGi application design - am I abusing the service framework?

查看:119
本文介绍了OSGi应用设计 - 我滥用服务框架吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们正在开发的应用程序中,我有一个用于实现数据提供程序组件的通用接口,我正在将这些提供者挂接为服务。



我的同事们建议,只需创建一个可以跟踪这些实现(目前有多少可用的服务,也可能通过getter将其提供给代码库的其他部分)的服务可能会更好,我们可以使用实施捆绑的激活器。



虽然这通常可以工作,但这几乎是(几乎)服务层首先提供的,对我来说,感觉就像我们



你怎么看?

解决方案

这将是复制功能。您的服务管理其他服务实际上成为服务注册表。



您现在有任何依赖于您的数据提供者的服务也取决于您的服务管理器,只有这样才能进行查找才能获得他们想要的实际服务。 p>

更好地将实际所需的依赖项注入到实际需要的代码中,并且有许多工具(DS,Spring DM,Blueprint ...)将提供此功能基于规范中定义的功能。就是服务注册表。



更新:如果您正在进行动态加载,那么OSGi已经为此提供了一个ServiceListener,消费者需要意识到这种性质并适当编码。上述工具也处理这些情况。


In an application we're developing I have a common interface for data provider components to implement, and I'm hooking these providers up as services.

One of my colleagues suggested it might be better to just create one service that can keep track of these implementations (how many are available currently, and perhaps make them available to other parts of the codebase via getters), and we could register/deregister them using the implementation bundle's activators.

While this could generally work, this is (almost) exactly what's provided by the service layer in the first place, and to me, it feels like we're duplicating functionality.

What do you think?

解决方案

That would be duplicating functionality. Your service to manage other services in effect becomes the service registry.

You now have any services dependent on your data providers also dependent on your service manager, and only so that they can do lookups to get the actual service they want.

Better to simply inject the actual required dependency into the code that actually needs it, and there are many tools (DS, Spring DM, Blueprint...) that will supply this functionality based on the capabilities defined in the specification. That is, the service registry.

Update: If you are doing dynamic loading, as you imply, then OSGi already provides a ServiceListener for this purpose, and consumers need to be aware of this nature and coded appropriately. The afore mentioned tools handle these cases as well.

这篇关于OSGi应用设计 - 我滥用服务框架吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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