|
|
|
Re: How do you inject the IEventBroker in an OSGi service ? [message #1005916 is a reply to message #1005913] |
Tue, 29 January 2013 09:55 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
You are putting it in the wrong context, you need to put it into the one
of your MApplication.
public class ControllerAddon {
@PostConstruct
void hookListeners(..., MApplication app) {
Controller ...
app.getContext(Controller.class, controller);
}
}
Tom
Am 29.01.13 10:52, schrieb Erik Vande Velde:
> Thanks for the fast reaction! Another suggestion we found on the web is
> to create a declarative service, and put it in a/the context thru an AddOn.
> Sample code fragment:
> ---
> public class ControllerAddon {
> @PostConstruct
> void hookListeners(IEclipseContext context) {
> Controller controller = ContextInjectionFactory.make(Controller.class,
> context);
> context.set(Controller.class, controller);
> }
> ---
> Here we can inject 1) the IEventBroker into that Controller class
> 2) our OSGi service into the same Controller, and delegate from the
> Controller to the OSGi service.
> The injection indeed works. If we set a breakpoint on the context.set
> above we see both injected fields. But when we inject our controller in
> a List Part we see another instance, with null IEventBroker and OSGi
> service. Do you have an idea why E4 creates a new controller for the
> List Part, instead of using the one we created in the AddOn?
> We put a @Singleton annotation on the controller, but that didn't help ...
|
|
|
|
Powered by
FUDForum. Page generated in 0.03064 seconds