|
|
|
|
|
|
|
|
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699501 is a reply to message #1699262] |
Wed, 24 June 2015 15:48 |
Alexander Baier Messages: 16 Registered: May 2015 |
Junior Member |
|
|
Dirk Fauth wrote on Tue, 23 June 2015 06:57I'm not sure about the question.
First, in E4 you do almost everything via injection. For the EPartService it is typically fine to do a field injection.
Ok, I will go down this route then. I was wondering, if there is some kind of lifecycle I have to be careful about, when working with the EPartService. E.g. does the service injected at object creation time (constructor, field) behave different than one, that is injected on a method call. Or, more to the point of my example, is it safe to use a PartService injected via the constructor after the constructor has finished executing.
Quote:Second, if you need to programmatically perform actions on the application model, you need to use the eclipse 4 services. Since you want to show different views dependent on your selection, IMHO using the EPartService is the correct way. If you only need to change the content of a view, you could give the ESelectionService a try.
I actually want to use multiple instances of the same view. How do I do that? Can I just call EPartService.createPart(String) multiple times? If yes, is there a build-in mechanism allowing me to differentiate between these multiple instances, or do I have to do my own book keeping?
Regards,
--
Alexander Baier
|
|
|
|
|
|
|
|
|
|
|
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706763 is a reply to message #1705580] |
Sun, 30 August 2015 16:55 |
Alexander Baier Messages: 16 Registered: May 2015 |
Junior Member |
|
|
I am now trying to make use of E4's dependency injection to properly declare the dependencies of my classes instead of pulling those out of public static <Dependency> INSTANCE fields all over the place.
I have a Part that I create and show via PartService#createPart(String) and PartService#showPart(Part, PartState). This Part's class has a dependency on Interface A which is to be set via the constructor of said class:
@Inject
public SomeClass(A dependency) { ... }
I want to bind A.class to an implementation before I create SomeClass, so it gets properly injected into the constructor. To do this, I try (and fail) to get a reference to the appropriate IEclipseContext:
EModelService modelService;
IEclipseContext ctx = modelService.getContainingContext(somePart);
ctx.set(A.class, new AImpl()); // NPE
part.setContext(ctx);
This, however, does not work. It throws an NPE because ctx is null.
What is the intended way of injecting dependencies into a class that is created by a Part?
Regards,
--
Alex
[Updated on: Sun, 30 August 2015 16:56] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02814 seconds