- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 11:29 AM
Hi,
I have a component that declares a service. The service has different implementations provided in separate bundles:
- BaseBundle:
- ServiceInterface
- BaseServiceImpl
- SecondBundle:
- SecondServiceImpl
- ThirdBundle:
- ThirdServiceImpl
The service and implementations are declared in a contribution in each bundle, like this:
// BaseBundle
<?xml version="1.0"?>
<component name="BaseBundleComponent">
<implementation class="org.example.service.impl.BaseServiceImpl"/>
<service>
<provide interface="org.example.service.ServiceInterface"/>
</service>
</component>
// SecondBundle
<?xml version="1.0"?>
<component name="SecondBundleComponent">
<require>BaseBundleComponent</require>
<implementation class="org.example.service.impl.SecondServiceImpl"/>
<service>
<provide interface="org.example.service.ServiceInterface"/>
</service>
</component>
// ThirdBundle
<?xml version="1.0"?>
<component name="ThirdBundleComponent">
<require>SecondBundleComponent</require>
<implementation class="org.example.service.impl.ThirdServiceImpl"/>
<service>
<provide interface="org.example.service.ServiceInterface"/>
</service>
</component>
So, the SecondBundle requires the BaseBundle (because it extends BaseBundle implementation). And the ThirdBundle requires the SecondBundle (for the same reason). I thought that with the requires I would be able to override the implementation of ServiceInterface:
- If I load Base + Second, the implementation should be SecondServiceImpl
- If I load Base + Second + Third, the implementation should be ThirdServiceImpl
But I've seen that it is not that way.
So what is the correct way to override the implementation of a service depending on the bundles that are loaded? Is it possible?
Thank you in advance,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 08:59 AM
As it turns out, I had a typo in the contribution of the third bundle, and that was the reason why it didn't work. So, using different implementations with requires actually works in my case.
Sorry for the mistake!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 08:59 AM
As it turns out, I had a typo in the contribution of the third bundle, and that was the reason why it didn't work. So, using different implementations with requires actually works in my case.
Sorry for the mistake!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 09:01 AM
Ok good to know thanks, that was surprising to me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 09:08 AM
Thanks! It's good to know.
