I’ve started looking a Au2 from the perspective of an Aurelia 1 application that relies heavily on the “enhance” feature of Aurelia.
I noticed in the docs that each enhanced element now gets its own DI container and I noticed that when using the EventAggregator a subscription created in one container would not fire when the event is published from another container (ie in an enhanced element).
To revert back to the more global behavior I have in the Aurelia 1 application I did the following in my main startup, where
au is the “main” aurelia instance and
registrations is an array where I store all global registrations (such as custom elements etc):
let globalEventAggregator = au.container.get(EventAggregator); registrations.push(Registration.instance(EventAggregator, globalEventAggregator));
registrations collection is then reused each time I enhance any other element within the application, so now my event publishing across different aurelia instances/DI containers works as I need it.
Is this a fine way to do it or am I doing something crazy here?