How does Dependency injection work in AngularDart?

Issue

Say I have a class, Logger, which is not a component, which uses ServiceA (marked as Injectable). Logger’s constructor look like:

Logger(this._logger);

Will AngularDart implicitly pass ServiceA to Logger upon instantiation even though Logger is not a component or directive? The AngularDart docs are unclear on this.

Solution

When Logger is instantiated by DI (AngularDart) it will try to resolve all dependencies (constructor arguments, also transitive) and pass them to the constructor or throw otherwise.

Answered By – Günter Zöchbauer

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.