|
|
|
Re: @Inject calls context function but ContextInjectionFactory.make does not. Why? [message #1386282 is a reply to message #1386279] |
Mon, 16 June 2014 10:53 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
On 16.06.14 12:46, Andreas Sewe wrote:
> Quote:
>> You get what you asked for -
>> ContextInjectionFactory.make(IPrivacySettingsService.class,eclipseContext)
>>
>> - requests to create an instance of IPrivacySettingsService. I suppose
>> what you wanted to make is an instance of an Object that retrieves the
>> IPrivacySettingsService.
>>
>> If you really want to obtain an instance of IPrivacySettingsService
>> you'd simply do eclipseContext.get(IPrivacySettingsService.class).
>
> Of course! Thank you.
>
> Quote:
>> One more warning - the
>> EclipseContextFactory.getServiceContext(bundleContext) - will give you
>> different context instances for each BundleContext!
>
> Yes, but the OSGi service should be available in all of them, so I won't
> run into problems, I think.
>
> Anyways, what's the preferred way to obtain something from the Eclipse
> context from old E3 code? That's where I currently use
> EclipseContextFactory.getServiceContext(bundleContext).
The preferred way is to grab the
org.eclipse.e4.ui.workbench.IWorkbench-Instance from the OSGi-Service
registry and/or to get the local IEclipseContext you can use
IServiceLocator s = ...;
IEclipseContext ctx = s.getService(IEclipseContext.class);
which IMHO is the best way because then you get the correct context for
your usage e.g. the one on the part, perspective, window, ... .
Tom
|
|
|
Powered by
FUDForum. Page generated in 0.02934 seconds