My sample classes:
public class MyModel implements Model
{
:
:
}
public class SingleModelProvider implements ModelProvider
{
public SingleModelProvider(Model providedModel, List actions)
{
:
}
}
The plan is to reuse the SingleModelProvider class in several bundles to provide different implementations of the ModelProvider. What I need to accomplish in each bundle is to simply instantiate the SingleModelProvider with the appropriate parameters to the constructor. A pretty simple scenario using any DI framework. I would like to register the ModelProvider services using DS (Declarative Services) if possible without having to write the boilerplate code in an Activator.
Is this possible?
I can’t seem to find any documentation on how to accomplish this since the class declaration in DS does not seem to allow for constructor arguments (or setters for that matter).
Do I use a factory? I am not sure if that is worthwhile since it may make the case no simpler than using an Activator and publishing service manually.
Is there a specific reason why you want to use DS?
You could also use the OSGI Blueprint services as described in the OSGI Service Compendium version 4.2, 121. It provides the best of two worlds: DI and easy service publishing / consuming.
In DS the only option as far as i know is to use the factory, the bind / unbind methods don’t accept user classes. (As described in the OSGI Service Compendium version 4.2, 112.4.5)