Skip to content

Introduce dependency injection to the project

Problem to solve

There are multiple ways of initializing services in the extension (using a constructor for context-independent services and an init method for context-dependent services). This makes it hard for contributors to know how to obtain an instance of a class, and it also makes it hard to introduce new services to the extension.

Proposal

Create one container containing all the created instances and use dependency injection to provide these instances to the rest of the extension.

We could create a custom lightweight library or reuse an existing one like https://github.com/inversify/InversifyJS

Further details

This was feedback that I received from @slashmanov and @fdegier, who recently contributed to the extension.

Links / references