Get access to aurelia root container in decorators

Hi @vipinrt, that infra is there, but the API is not there yet for friendly public consumption. For example, it can be accessed like this:

// if you are using the `aurelia` umbrella package

const aurelia = Aurelia.app(...);
const rootContainer = aurelia.container;

// if you are not using the said package
const aurelia = new Aurelia();
const rootContainer = aurelia.container;

Another way would be to grab the container instance while registering the plugin. Typically the plugin configuration object has a register(container: IContainer) method. The container can be grabbed can cached there as well.

However, note that if you have multiple "root"s in you app, you can technically have multiple instances of Aurelia to hydrate the DOM. So in that sense, there is no one true “root” container.

Moreover, let me also point out here that the lack of API is not accident IMO. I believe there are better ways to do things in Au2, which is why the static API is bit sparse in Au2. IMO having static API is bit problematic for testing.

In that light, if you can be more specific about what you want to achieve, I am sure the community members can come up with way better ideas.

Have fun with Au2 :slight_smile:

5 Likes