Reputation: 13
Can someone please explain me how to use Eclipse E4 DI feature to inject my custom services/providers?.
@Singleton
public class ConnectionPool {
// should be a singleton
}
public class MyService implements IMyService {
@Inject
ConnectionPool pool;
}
// referenced in application model
public class SamplePart {
@Inject
IMyService myService;
@PostConstruct
public void createComposite(Composite parent) {
myService.doSomething();
}
}
Or is it possible to use Google Guice (for example) together with Eclipse DI?
I tried few examples (like this) but it's not working for me
Upvotes: 1
Views: 924
Reputation: 111142
You need to add the @Creatable
annotation to ConnectionPool
(org.eclipse.e4.core.di.annotations.Creatable
):
@Singleton
@Creatable
public class ConnectionPool
You could also use an OSGi service for the service. It is also possible to create the service in an AddOn or in the the application LifeCycle class. You can also use a ContextFunction
to create a service.
Upvotes: 2