isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GESCONSULTOR - Óscar Bou <o....@gesconsultor.com>
Subject Re: Services still not injected when entering @PostConstruct methods on a Service
Date Tue, 19 Nov 2013 08:34:47 GMT
Thanks, Dan.

Tickets created.

Regards,

Oscar


El 19/11/2013, a las 08:19, Dan Haywood <dan@haywood-associates.co.uk> escribió:

> Hi Oscar,
> I agree this should change.  Could you raise a JIRA ticket for this? and
> I'll have a look at changing it.
> 
> On a related note (though probably a separate ticket), I reckon we should
> also support @Inject (on the field name) rather than the use of a setXxx()
> or injectXxx() method.
> 
> Cheers
> Dan
> 
> 
> On 17 November 2013 16:29, GESCONSULTOR - Óscar Bou
> <o.bou@gesconsultor.com>wrote:
> 
>> 
>> Just to point it out, as per [1] and [2], @PostConstruct should only be
>> called after all dependencies have been injected.
>> 
>> Thanks again,
>> 
>> Oscar
>> 
>> 
>> [1]
>> http://docs.oracle.com/javaee/5/api/javax/annotation/PostConstruct.html
>> 
>> [2]
>> http://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection#.40PostConstruct.2C_.40PreDestroy_.28javax.annotation.29
>> 
>> 
>> 
>> 
>> El 17/11/2013, a las 17:15, GESCONSULTOR - Óscar Bou <
>> o.bou@gesconsultor.com> escribió:
>> 
>>> Hi to all.
>>> 
>>> I have an Isis service that needs to initialize a "server" upon creation
>> (it's a Drools session, but it would be the same with an email server, for
>> instance).
>>> 
>>> For initializing that "server", I need to pass it references to other
>> Isis services (in this case Drools globals).
>>> 
>>> If, as per [1], I try like this:
>>> 
>>>   @PostConstruct
>>>   public void init(final Map<?, ?> props) {
>>> 
>>>      server.setGlobal("eventOccurrences", this.eventOccurrences);
>>> 
>>> 
>>>   }
>>> 
>>>   ....
>>> 
>>>   // {{ injected: EventOccurrences
>>>   private EventOccurrences eventOccurrences;
>>> 
>>>   public final void injectEventOccurrences(final EventOccurrences
>> eventOccurrences) {
>>>       this.eventOccurrences = eventOccurrences;
>>>   }
>>> 
>>>   // }}
>>> 
>>> 
>>> The problem is that when the execution arrives to:
>>> server.setGlobal("eventOccurrences", this.eventOccurrences);
>>> 
>>> 
>>> this.eventOccurrences is still null... So it has not yet been injected
>> (or instantiated).
>>> 
>>> I must ensure that the server starts to run from the beginning of the
>> Isis application execution.
>>> 
>>> There's a note on [1] footer, but I thought this is not the case, as my
>> only expectation is that services are injected when calling
>> "@PostConstruct" methods.
>>> 
>>> 
>>> Perhaps I'm missing something basic or the previous expectation is
>> precisely the one explicited by the footer note ...
>>> 
>>> If that's the case, is there a better way to solve it?
>>> 
>>> 
>>> Thanks,
>>> 
>>> Oscar
>>> 
>>> 
>>> [1] http://isis.apache.org/core/services/initializing-services.html
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
>> 


Mime
View raw message