|Is deferring method injection after PostConstruct possible? [message #1807684]
||Thu, 06 June 2019 06:37
| Guido Schnepp
Registered: March 2013
I have a specific problem with dependency injection order in my e4 RCP application. Hope you have an answer for me on how to proceed here:
Being currently designed as a multi-perspective application I'm trying to handle over a setting, basically the selected file, from one perspective to another using DI for this and an own object. I use the MTrimmedWindow context for this, being available in all sub-perspectives of that window. This works great! But ...
Dependency injection order* is a little problem here since my @Inject annotated receiving method runs before @PostConstruct was able to initialize the necessary widgets like a TreeViewer an others. This is true for the first selection of the target perspective only, which means perspective's parts are initialized on first invocation/presentation (which is ok) but DI happens in "wrong" order in this case.
I can imagine different solutions:
1. Create parts in target perspective early so that PostConstruct is run before object is set to context (how?)
2. Defer method injection after PostConstruct (how?)
4. Catch and store object in method, look, if target widgets have been created already (= PostConstruct is run) and proceed either immediately or a the end of PostConstruct (by hand, on the stored object).
No. 4 is my current solution but far from being the best one, I assume, since I loose the benefits from generic context injection a little bit.
On a completely different matter: Using perspectives and a self-made perspective switcher may not be the best design decision here, but the most logical to me: How would you solve a RCP application with different (full-size) views to change between via view selector? A single-perspective app with top-level part stack would have the same problem here I think, that inner parts are initialized not before first invocation.
Many thanks in advance!
Powered by FUDForum
. Page generated in 0.02156 seconds