You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Alex Sviridov <oo...@mail.ru> on 2015/07/14 06:48:36 UTC

OSGI: DS+CDI and component factories issues

I use apache felix +weld+pax. To work with DS I use annotations (@Service,@Component).  
What I need is to get new instance of declarative service every time when some consumer needs this service + using CDI. 
And as I understand I can do it only using component factory. (Maybe scope=prototype can also help - I couldn't find the answer and how to do it).

 I've read a lot of articles and I can't find the answer to 2 my questions.

1)If we use factories, why in service consumer we call factory (http://www.rpgnextgen.com/wiki/doku.php?id=component_factory ) and after that we get reference to service. I mean

    // get factory
    ComponentFactory factory = (ComponentFactory) context.getService(serviceReferences[0]);
    // get instance
    ComponentInstance instance = factory.newInstance(null);

2) Is there no way to set factory with certain interface and in service consumer call service when osgi inside calls the factory?

    If in service consumer we call factory then why we mark service as component when de facto factory is component?

The problem is that without factory I do @Inject @OsgiService (javase) or@OSGiService (javaee) and I can use different filters and code is very clear. Using component factory I (as I understand) loose this ability.

Please, help me.

-- 
Alex Sviridov