Spicefactory Forum Index Spicefactory
Forum Archive
 
 SearchSearch    Log inLog in 

How static objects initialization is ordered?

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory
View previous topic :: View next topic  
Author Message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Fri Jul 19, 2013 11:37 am    Post subject: How static objects initialization is ordered? Reply with quote

Hi Jens (or anyone who can answer)

Can you confirm that Objects declared in an MXML context as direct MXML instances (eg. <SomeClass> instead of <Object type="SomeClass" /> are initialized:
- BEFORE the dynamic objects (<Object> tag)
- and in an unpredictable order.

Here is the code from Parsley 2.4 that suggests this:

DefaultContext.initializeSingletons()
...
for each (var id:String in _registry.getDefinitionIds()) {

...
where _registry.definitiions is the keys of SimpleMap, so unordered.

Thanks
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Sun Jul 21, 2013 8:27 pm    Post subject: Reply with quote

In general the initialization order of objects is unpredictable, and this is on purpose: it would go against the encapsulation effort you usually want to achieve with an IOC container if you'd need to rely on a specific order.

There are two exceptions though:

  • When there is a dependency between two objects, the dependency will be initialized first. Only exception from this exception are bidirectional or circular dependencies where this is simply not possible.
  • When the order has been explicitly set with the order attribute as described in section 8.4 in the manual. But again, if you need to use this option a lot it might hint at a problem in your application design. And the explicit order still might get overridden by order requirements triggered by dependency resolution.

For the other question: No, there is no difference in initialization order between Parsley's Object tags and direct MXML instances. They are initialized intertwined, in unpredictable order with the two exceptions mentioned above.

The only difference is that in the case of a direct MXML instance, the object does not get instantiated by Parsley, but instead by the Flex framework, and that, of course, happens before anything else. But this is really merely instantiation (constructor invocation), none of the object configuration (injections, etc.) get processed at that stage.

Hope that helps. You are lucky I still remember these details. Smile
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Fri Jul 26, 2013 12:09 pm    Post subject: Reply with quote

Thank you Jens for the detailed information and for the quick response.
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group