Hi,
I have a component that declares a service. The service has different implementations provided in separate bundles:
- BaseBundle:
- ServiceInterface
- BaseServiceImpl
- SecondBundle:
- ThirdBundle:
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,