How do you inject the IEventBroker in an OSGi service ? [message #1005889] |
Tue, 29 January 2013 03:45  |
Eclipse User |
|
|
|
In an MVC world you want to send events from a controller/service, not from a view object. In our project that controller is an OSGi service, as we create it with spring dynamic modules (to use spring based remoting). How can we send events thru the IEventBroker from this non E4 service?
|
|
|
|
|
Re: How do you inject the IEventBroker in an OSGi service ? [message #1005916 is a reply to message #1005913] |
Tue, 29 January 2013 04:55   |
Eclipse User |
|
|
|
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.04214 seconds