[英]creating a unique service instances using Componentfactory by without using servicefactory in OSGI
I am trying to use component factory in OSGi. 我正在尝试在OSGi中使用组件工厂。 My intention is to create instances of Class A, which is exposed as a factory, using Class B, which is a factory manager.
我的意图是使用工厂经理B类创建A类实例,该实例作为工厂公开。 Class A contains some services with @Reference annotations which work fine.
类A包含一些带有@Reference批注的服务,它们可以正常工作。 The same approach is used for Class C, factory (as similar to Class A) with same service references with @Reference.
对于具有@Reference的相同服务引用的C类工厂(与A类相似)使用相同的方法。
ServiceFactory behavior is independent of DS. ServiceFactory的行为独立于DS。 Assuming you are not using the new PrototypeServiceFactory in R6, a bundle making multiple gets for a ServiceFactory service will see the same service object.
假设您未在R6中使用新的PrototypeServiceFactory,则为ServiceFactory服务进行多次获取的捆绑包将看到同一服务对象。 Different bundles will see different service objects (assuming the ServiceFactory implementation returns distinct objects).
不同的捆绑包将看到不同的服务对象(假设ServiceFactory实现返回不同的对象)。
So if A and C are in the same bundle, they will see the same service object for referenced services independent of whether the referenced service is a ServiceFactory. 因此,如果A和C在同一个包中,则对于引用的服务,它们将看到相同的服务对象,而与引用的服务是否为ServiceFactory无关。
If you need distinct service objects, you should look into PrototypeServiceFactory added in Core R6 and supported in DS 1.3. 如果需要不同的服务对象,则应查看Core R6中添加的DS 1.3中支持的PrototypeServiceFactory。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.