I am looking for a simple way to control the instantiation of a declarative service.
What I want is something like a factory which is asked to return an instance of a component, but where I can control the instantiation.
Currently I just found the ComponentFactory where I just can call newInstance with a given dictionary. But what I really want, is something like this, assuming IComponent is the declarative service interface and MyComponent is the implementation class
public class MyComponentFactory implements ? {
public IComponent newInstance() {
return new MyComponent("firstParameter", "secondParameter");
}
}
Is there something possible like this with declarative services, or do I need to use my own service registration in a bundle activation code?
Thanks in advance
DS does not provide for the level of instance creation indirection you are looking for. DS will always use the public no-args constructor and then call the specified activator method to complete the instance initialization.