Now with the @Creatable annotation is possible to mark a class to be injected without adding it in the EclipseContext by hand in the life cycle:
http://blog.vogella.com/2012/02/29/eclipse-4-is-now-a-full-dependency-injection-container-with-creatable/
However, what about the following scenario: lets say that I have an interface SomethingService and some number of implementations, and I want to refer to one of those (i.e. the one annotated as creatable) by its interface, something like:
@Creatable
class Todo implements SomethingService {
@Inject
public Todo(SomeArg arg) {
// placeholder
}
}
// Field Injection
@Inject private SomethingService service; // Todo instance
This doesn’t seem to work at all. Is there a way to achieve what I need?
Well, from what I could see what I'm asking should be done with the OSGi Declarative Services or like the example from "Eclipse 4 Plug-in Development by Example" modifying the Activator like this:
public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws
InjectorFactory.getDefault().
addBinding(IStringService.class).implementedBy(StringService.class);
}
}
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With