Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 DI best practices(E4 DI best practices)
E4 DI best practices [message #736121] Thu, 13 October 2011 16:00 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 9
Registered: July 2009
Junior Member
Hi,

- In a ViewPart object, use e4 DI to use E4 services. Good and I'm sure it's a best
practice Wink

- In my Java objects called from ViewPart, e4 DI not available so i call my objects with a reference of my E4 service. Is it a best practice ?

- In my OSGI services,I can't use E4 services because IEclipseContext was created only for my E4 application.
Ok, so i don't use OSGI services and put all classes in my E4 application if i need e4 di ? Is there another solution ?


Thanks

Re: E4 DI best practices [message #736191 is a reply to message #736121] Thu, 13 October 2011 19:01 Go to previous messageGo to next message
Thomas Blattner is currently offline Thomas BlattnerFriend
Messages: 5
Registered: July 2010
Junior Member
Hello,
regarding your point 2.
There is a (or even several) way to inject e4 Services into Java objects.

Have a look at this tutorial www.vogella.de/articles/EclipseE4/article.html#programmingmodel_ownobjects

@Thanks to Lars for his good work on all his tutorials!
Re: E4 DI best practices [message #736204 is a reply to message #736121] Thu, 13 October 2011 19:42 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 13.10.11 18:00, schrieb jyl:
> Hi,
>
> - In a ViewPart object, use e4 DI to use E4 services. Good and I'm sure
> it's a best
> practice ;)
>
> - In my Java objects called from ViewPart, e4 DI not available so i call
> my objects with a reference of my E4 service. Is it a best practice ?
>

I use ContextInjectionFactory.make/.... in my custom code as well. DI
should NOT end at your Part-class.

> - In my OSGI services,I can't use E4 services because IEclipseContext
> was created only for my E4 application.
> Ok, so i don't use OSGI services and put all classes in my E4
> application if i need e4 di ? Is there another solution ?
>

Well this is an open topic to me as well I'd really like us to get
access to the IEclipseContext in OSGi-Services as well. For single user
envs the solution is simple but I've not yet had an idea how to make
this work with multi-user envs so until today you have to live without
DI in OSGi-Services unless you implement the access your own.

Tom
Re: E4 DI best practices [message #787354 is a reply to message #736191] Tue, 31 January 2012 13:44 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Thanks Thomas for the recommendation. I recently reworked to tutorial. Its now available: Eclipse 4 Application Development.

It also describes how to use DI for POJO's, e.g. not objects based on the model.
Re: E4 DI best practices [message #834695 is a reply to message #787354] Mon, 02 April 2012 09:18 Go to previous messageGo to next message
Laura V is currently offline Laura VFriend
Messages: 32
Registered: March 2012
Member
Lars, Tom, a question
I tried the code in your tutorial, seems logic but in my case it doesn't work.

I need to use my PartHelper class in an OSGI Service.
My PartHelper class needs the following injected variables:
@Inject private EModelService modelService;
@Inject private MApplication application;
@Inject private EPartService partService;

Tried to put this code in my service:

Bundle bundle = FrameworkUtil.getBundle(getClass());
BundleContext bundleContext = bundle.getBundleContext();
IEclipseContext eclipseCtx = EclipseContextFactory.getServiceContext(bundleContext);
ContextInjectionFactory.make(PartHelper.class, eclipseCtx);

The MAKE doesn't work, it can't inject the parts obviously because I am in the wrong context. How can I access the application context from here? Is there a way to do it at all?
Thanks

Laura
Re: E4 DI best practices [message #840793 is a reply to message #834695] Tue, 10 April 2012 14:14 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

No you can't get access to applications IEclipseContext in an
OSGi-Service. The problem is that while in a desktop environment there's
(very likely a 1:1 relationship between a running OSGi and Application)
but as soon as you e.g. think about RAP this 1:1 relations is not true
any more.

The question now is why you are using the OSGi-Service to interact with
your application?

Tom

Am 02.04.12 11:18, schrieb Laura V:
> Lars, Tom, a question
> I tried the code in your tutorial, seems logic but in my case it doesn't
> work.
>
> I need to use my PartHelper class in an OSGI Service.
> My PartHelper class needs the following injected variables:
> @Inject private EModelService modelService;
> @Inject private MApplication application; @Inject private
> EPartService partService;
>
> Tried to put this code in my service:
>
> Bundle bundle = FrameworkUtil.getBundle(getClass());
> BundleContext bundleContext = bundle.getBundleContext();
> IEclipseContext eclipseCtx =
> EclipseContextFactory.getServiceContext(bundleContext);
> ContextInjectionFactory.make(PartHelper.class, eclipseCtx);
>
> The MAKE doesn't work, it can't inject the parts obviously because I am
> in the wrong context. How can I access the application context from
> here? Is there a way to do it at all?
> Thanks
>
> Laura
>
Previous Topic:Really need the book on this
Next Topic:Split application model
Goto Forum:
  


Current Time: Fri Apr 19 22:10:22 GMT 2024

Powered by FUDForum. Page generated in 0.03866 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top