Hi Nuwan,
You can observe a reference to IEclipseContext using the bundleContext
object. You can get a reference to bundleContext via bundle activator or
via FrameworkUtil class.
See following snippet.
BundleContext bundleContext =
FrameworkUtil.getBundle(SomeClassInYourBundle.class).getBundleContext();
IEclipseContext eclipseContext =
EclipseContextFactory.getServiceContext(bundleContext);
BTW, how did you try to get a IEventBroker reference via Dependency
Injection?
If you are getting null for injected references always, I suspect that DI
engine does not manage your object.
FYI, Eclipse E4 DI engine only manages classes in Application Model or
framework components by default (eg. commands, handlers, activators,
declarative services, etc.). If your class is not a framework component and
you manually instantiate it in your code using *new *operator, DI engine is
not aware of that. In such kind of a situation, you need to manually inject
the required references using ContextInjectionFactory. See following
snippet.
YourClass object = new YourClass();
ContextInjectionFactory.inject(object, eclipseContext);
For the ContextInjectionFactory.inject method, you need to pass the DI
context (to tell DI engine from which context to obtain references which
are needed to inject - this should be the global eclipse context in most
cases) and your object. You can obtain the global eclipseContext using
first snippet.
For example, you can use below code to get a reference to IEventBroker in a
custom class which is not a framework component.
public YourClass{
@Inject
IEventBroker eventBroker;
public YourClass(){}
}
Then, inject reference while instantiating.
BundleContext bundleContext =
FrameworkUtil.getBundle(YourClass.class).getBundleContext();
IEclipseContext eclipseContext =
EclipseContextFactory.getServiceContext(bundleContext);
YourClass object = new YourClass();
ContextInjectionFactory.inject(object, eclipseContext);
HTH.
Thanks,
On Tue, Nov 3, 2015 at 9:07 PM, Nuwan Pallewela <[email protected]> wrote:
> Hi Devs,
>
> I'm trying to get a IEclipseContext object to get IEventBroker. DI method
> to get IEventBroker instance always gives a null. Alternative method to get
> IEventBroker is through IEclipseContext instance. DI method to get it also
> not working. Is there any way to get a instance of IEclipseContext object?
>
> Thanks,
> Nuwan
>
> --
> ----------------------------------------------------------
>
> *Nuwan Chamara Pallewela*
>
>
> *Software Engineer*
>
> *WSO2, Inc. *http://wso2.com
> *lean . enterprise . middleware*
>
> Email *[email protected] <[email protected]>*
> Mobile *+94719079739 <%2B94719079739>@*
>
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
--
*Kavith Lokuhewage*
Software Engineer
WSO2 Inc. - http://wso2.com
lean . enterprise . middleware
Mobile - +9477-9-145-123 | +9471-455-6-401
Linkedin <http://www.linkedin.com/pub/kavith-lokuhewage/49/473/419> Twitter
<https://twitter.com/KavithThiranga>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev