If you need an injectable service, such as the
IEventBroker
, in a class that is not subject to DI per default, you can trigger DI manually:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
MyPoJoClass { @Inject private IEventBroker eventBroker; public MyPoJoClass { inject(); } private void inject() { IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(Activator.getContext()); ContextInjectionFactory.inject(this, serviceContext); } private void inject2() { IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(Activator.getDefault().getBundle().getBundleContext()); ContextInjectionFactory.inject(this, serviceContext); } public void fireSomeEvents(Object data){ eventBroker.publish("My_Event", data) } } |