In my testing
Code:
X. parentApplicationContext.addChildContext(childMXMLApplicationContext.applicationContext)
IS OK, but MUST be moved to the event on child context completed.
And autowired will not work due to parent can not handle the child context.
If I move [X] line to the module just created, then it will trigger codes below:
Code:
core: ../context/impl/ApplicationContext
383. public function addChildContext(childContext, settings):IApplicationContext
...
392. if (settings.shareDefinitions) {
393. addDefinitionsToChildContext(childContext, objectDefinitionRegistry);
394. }
and then will trigger
Code:
flex: ../context/impl/mxml/MXMLApplicationContext
227. public function get objectDefinitionRegistry():IObjectDefinitionRegistry {
228. return _applicationContext.objectDefinitionRegistry;
229. }
yet the _applicationContext has not built.
Also I tried childContext.applicationContext = parentContext, before the childContext initialized, and it will raise another problem:
Code:
flex: ../context/impl/mxml/MXMLApplicationContext
350. public function initializeContext():void {
351. if (!_contextInitialized) {
352. if (_applicationContext == null) {
353. var rootViews:Vector.<DisplayObject> = (_document != null) ? new <DisplayObject>[(_document as DisplayObject)] : null;
354. _applicationContext = new DefaultApplicationContext(null, rootViews);
355. }
356.X _applicationContext.addDefinitionProvider(new MXMLObjectDefinitionsProvider());
...
X line will trigger
Code:
core: ../context/impl/ApplicationContext
409. public function addDefinitionProvider(provider:IObjectDefinitionsProvider):IApplicationContext {
410.X if (definitionProviders.indexOf(provider < 0)) {
...
But definitionProviders has already been set to null when in
Code:
693. protected function cleanUpObjectDefinitionCreation():void {
...
706. _definitionProviders.length = 0;
707.? _definitionProviders = null;
...
I try to comment line 707, but after that, everything is UnOK, that maybe means the child context really can not share parent's _applicationContext, and must have it's own DefaultApplicationContext. So, at last, I give up setting the childContext.applicationContext, and finally making parentContext.addChildContext when childContext is initialized.
And, the eventbus matter, U can see ApplicationContext about
Code:
core: ../context/impl/ApplicationContext
383. public function addChildContext(childContext, settings):IApplicationContext
...
389. if (settings.shareEventBus !== EventBusShareKind.NONE) {
390. addChildContextEventBusListener(childContext, eventBus, settings.shareEventBus);
391. }
MXMLApplicationContext doesn't implements IEventBusAware, in the begining, I extends MXMLAppContext with implements IEventBusAware and link the get eventBus() function to the applicationContext field's eventbus, and it then can get the message from parent, yet MUST NOT set the topic. After that, I study the eventbus code, I found that in IEventBus, the function is defined as:
Code:
/**
* Adds the given listener object as a listener to all events sent through the event bus.
*/
function addListener(listener:IEventBusListener, useWeakReference:Boolean=false, topic:Object=null):Boolean;
And, null isn't mean ANY_TOPIC, but THE TOPIC "NULL". So, link bus to each other seems will definitely lost the topic function point. So, finally, I just replace child context bus to parent contxt bus, and this is OK.
All demo codes U will see in my attachment before. Wish it will make a little help about the implementation.
And, thank you for reply me again.