Could you shed some light on why Aurelia.register(LoggerConfiguration.create(console)
in startup.ts
doesn’t work?
It should work. Are you not getting a logger when you try to inject it like so?
export class App {
constructor(@ILogger private logger: ILogger) {}
}
Must I create my own DI container and use it at Aurelia init time? I thought Aurelia.register() was a call against the ‘default’ container and hoped it would suffice.
There is no ‘default’ container. The constructor of the Aurelia
class is:
constructor(container: IContainer = DI.createContainer()) {
My example just so happens to be a straight forward way to keep a hold of the root container for your app. You can also peel it out of the Aurelia instance via the .container
property.
I consider it a best practice to avoid console.log (… and it’s a dependency on a global variable
This kind of answers your other question:
I’ve used the Aurelia1 logger in other projects (not Aurelia) with great success for years. Curious what motivated rewriting it for AU2?
Many of the problems in Aurelia 1 weren’t directly visible to users, but manifested in maintenance problems that the core team suffered from and made it harder for us to keep evolving and improving the framework. This is part of why Aurelia 1 has so many open issues and PRs that remained unresolved for years: many things are too hard to test, and we have no reliable means to prevent regressions.
Relying on mutable module-scoped variables is one of the major contributing factors, which is why (at least in non-legacy mode) we’re getting rid of module-scoped container and logger. There will be a legacy package that keeps these in to ease migration for existing apps, but we would recommend a slight change in approach for greenfield projects.
We’ll make sure to explain this in detail with plenty of examples as we get closer to release. It’s not something I can be spending too much time on right now.
But in summary, these types of changes make Aurelia 2 easier for us to maintain, test and improve upon, which allowed us to address almost all feature requests of Aurelia 1 and add even more powerful api’s and features that will save users more time in building ambitious applications.