Home » Eclipse Projects » Eclipse 4 » Hook in, after the MApplication context is filled by Services?
Hook in, after the MApplication context is filled by Services? [message #989004] |
Tue, 04 December 2012 04:43  |
Eclipse User |
|
|
|
Is there a way to hook in, in order to do something with the MApplicationContext,
directly after Services like EHandlerService, ECommandService are inserted into it?
I need a pointer to the MApplication-Context,
directly after Services are inserted in order to reuse the EHandlerService, ECommandService etc. in my objects,
which can not inject the Services because they are not part of the e4 Model.
|
|
| | | | | | |
Re: Hook in, after the MApplication context is filled by Services? [message #989033 is a reply to message #989020] |
Tue, 04 December 2012 06:12   |
Eclipse User |
|
|
|
Am 04.12.12 11:44, schrieb Alex Kipling:
> Thnx Dirk. I am fighting an additional problem, which I initiall was not
> aware of:
>
> The Context, which I get inside the LifeCycleManager is different, from
> the context, which I to get inside my Model-Parts.
>
Yes that is expected. Contexts are hiearchical, we create a context for
each element in the model which inherits from MContext (e.g.
MApplication,MWindow,MPerspective,MPart)
Tom
|
|
| | | | | | | |
Re: Hook in, after the MApplication context is filled by Services? [message #989260 is a reply to message #989105] |
Wed, 05 December 2012 06:47   |
Eclipse User |
|
|
|
What I did was:
Instantiating a creatable Class X Inside a Handler. The instantiateion was triggered inside a @PostConstruct method.
Handler{
..
@PostConstruct
OnPostConstruct(X myClassXObject){
}
@Creatable
X{
@Inject
EHandlerService handlerService;
@Inject
ECommandService commandService;
@Inject
MApplication app;
}
As seen the Class X required a pointer to the services, and the MApplication.
First I had to move the instantiation of X to a later time, by using IEventBroker.
Then I found out, that annotation the Handlers by @Optional makes the construct work.
The Handlers are not available at creation time of X,
but when X's methods are used - the Services are allready there.
Question:
Can seomone explain me, why the Injected Objects are empty on constuction, but non empty on method execution?
Does the System monitor @Optional Objects, where Injection failed and injects them later, as soon as a fitting Object becomes available?
Handler{
..
@PostConstruct
OnPostConstruct(X myClassXObject){
}
@Creatable
X{
@Optional
@Inject
EHandlerService handlerService;
@Optional
@Inject
ECommandService commandService;
@Optional
@Inject
MApplication app;
}
|
|
|
Re: Hook in, after the MApplication context is filled by Services? [message #989270 is a reply to message #989260] |
Wed, 05 December 2012 07:43   |
Eclipse User |
|
|
|
The question remains why are you creating this instance of X. Why can't
you do that when the handler is really executed? What does this X do
that it has to be created when the handler is created.
Even if this would work as I outlined before the context that creates
the handler is completely a different one than the context in which the
handler is executed (=context of the currently active MPart).
There is no guarantee that the EHandlerService and ECommandService are
not bound to the invoking context and only work there appropriately
(e.g. there are handlers available on different levels and it depends on
the current active area which one take precendence).
Tom
Am 05.12.12 12:47, schrieb Alex Kipling:
> What I did was:
> Instantiating a creatable Class X Inside a Handler. The instantiateion
> was triggered inside a @PostConstruct method.
>
> Handler{
> .
> @PostConstruct
> OnPostConstruct(X myClassXObject){
>
> }
>
> @Creatable
> X{
> @Inject
> EHandlerService handlerService;
>
> @Inject
> ECommandService commandService;
>
> @Inject
> MApplication app;
> }
>
>
> As seen the Class X required a pointer to the services, and the
> MApplication. First I had to move the instantiation of X to a later
> time, by using IEventBroker.
>
> Then I found out, that annotation the Handlers by @Optional makes the
> construct work.
> The Handlers are not available at creation time of X, but when X's
> methods are used - the Services are allready there.
>
> Question:
> Can seomone explain me, why the Injected Objects are empty on
> constuction, but non empty on method execution?
> Does the System monitor @Optional Objects, where Injection failed and
> injects them later, as soon as a fitting Object becomes available?
>
>
> Handler{
> .
> @PostConstruct
> OnPostConstruct(X myClassXObject){
>
> }
>
> @Creatable
> X{
> @Optional
> @Inject
> EHandlerService handlerService;
>
> @Optional
> @Inject
> ECommandService commandService;
>
> @Optional
> @Inject
> MApplication app;
> }
>
|
|
| |
Re: Hook in, after the MApplication context is filled by Services? [message #989386 is a reply to message #989273] |
Wed, 05 December 2012 19:59  |
Eclipse User |
|
|
|
But why is this done in a Handler? Why are you not simply contributing
an addon which points to X?
Tom
Am 05.12.12 14:12, schrieb Alex Kipling:
> Hello Tom,
> I felt, like it is no important - what the X does in @PostConstruct,
> but if you think that it is important:
>
> The Handler registers some IAdapterFactory objects to the Platform.
> It does not use the Context, here. Later the registered Factories are
> executed in the right Context, so everything works fine.
|
|
|
Goto Forum:
Current Time: Wed Jul 23 12:39:53 EDT 2025
Powered by FUDForum. Page generated in 0.26955 seconds
|