Community
Participate
Working Groups
Build Identifier: I20110620-1631 I'm currently implementing an e4 application based on eclipse 4.1. I've created an OSGI bundle (session bundle) which provides an declarative service "ISessionService". It is declared with immediate="true" and the start level of the bundle is below the start level of the application bundle. I want to have eclipse inject an instance of my ISessionService into my LoginHandler, which is declared as a command handler in the application defining XMI. During startup the following exception is thrown: org.eclipse.e4.core.di.InjectionException: Unable to process "LoginHandler.m_ss": no actual value was found for the argument "ISessionService". The LoginHandler class: public class LoginHandler { @Inject ISessionService m_ss; @Execute public void execute(IEclipseContext context) { m_ss.dosomething(); // details omitted... } } If I create an instance of the service in the bundle activator of the session bundle, anything works fine. BundleActivator: @Override public void start(BundleContext bundleContext) throws Exception { s_Context = bundleContext; ISessionService sservice = new SessionService(); s_Context.registerService(ISessionService.class.getName(), sservice, null); } In my understanding of e4 injection this shouldn't be necessary, isn't it? Best Markus Reproducible: Always
Oleg, any ideas?
It doesn't look like a problem with E4 since it works when you programmatically register your service. A more interesting example would be programmatically retrieving your service (with context.getServiceReference(ISessionService.class)) to see if it's properly registered. Markus, if you enable Equinox' console (-console as a launching option), is your component listed and satisfied if you type "ls" (list components)?
(In reply to comment #2) > It doesn't look like a problem with E4 since it works when you programmatically > register your service. A more interesting example would be programmatically > retrieving your service (with > context.getServiceReference(ISessionService.class)) to see if it's properly > registered. > > Markus, if you enable Equinox' console (-console as a launching option), is > your component listed and satisfied if you type "ls" (list components)? Sorry my fault! It turns out, that the SessionServiceImpl, which implements ISessionService, had a dependency to another service, which wasn't available at application startup. I removed the dependency and the service gets injected as expected. Sorry again. I did not realize that the instantiation of services is deferred until all dependencies are resolved.
(In reply to comment #3) > It turns out, that the SessionServiceImpl, which implements ISessionService, > had a dependency to another service, which wasn't available at application > startup. I removed the dependency and the service gets injected as expected. > Sorry again. I did not realize that the instantiation of services is deferred > until all dependencies are resolved. Yes, DS will behave this way if a reference is set as mandatory (1..1 or 1..n) and static. If you want another behavior, you can set it to optional and/or dynamic. Be careful that setting it static and optional (0..1) will mean that if it's not satisfied at the time the component is activated, it will never be satisfied. Closing this issue.