Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use interface with DI and @Creatable in E4 application

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?

like image 635
mreparaz Avatar asked Aug 15 '26 06:08

mreparaz


1 Answers

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

like image 51
mreparaz Avatar answered Aug 16 '26 21:08

mreparaz