Dependency Injection & Extension Manager

Last modified by Manuel Leduc on 2023/10/16 16:42

Dependency Injections Frameworks

Quite interesting article about dependency injection in Javascript: https://snyk.io/blog/dependency-injection-in-javascript/

Vue has dependency injection between the Vue modules using the "provide", "inject" functions.

Some frameworks to investigate:

In the prototype being worked on, inversify has been used successfully. There are some concerns that the project is not very active. The other frameworks should be tested also.

The inversify library has been succesfully used in combination with dynamic loading of extensions and also with static building which makes debugging easier.

Dynamic loading

Different systems support dynamic loading of javascript code. The question will be how to package more than one JS file.

There are multiple popular package managers which have features for dynamic loading but there are some difficulties to overcome, in particular concerning shared libraries.

Webpack module federation

It seems possible to bundle multiple apps as webpack packages which can load each other. This could be a good way to dynamically load modules from a configuration. Our modules could contain components implementing specific APIs.

Plugin systems

Extensions build with Standard Javascript modules

By using vitejs (or rollup) it is possible to build standard javascript modules.

These modules can be loaded dynamically as extensions and provide components to inversify allow to extend the features.

Static bundling can also been turned on to bundle some of the external modules in the main package.

In the prototype being worked on, extensions have been packaged as "standard JS Modules" with an entry point loading components using inversify.

Circular dependencies between extensions has not been experimented. To keep things simple, key APIs have been moved to an "api" module loaded first by all extensions.

The approach is compatible with VSCodium seeing the dependencies between the code (using a mono-repository).

Choice Matrix

FrameworkAcceptabilityGitHub LinkMaintainerLicenseProject ActivityTypescriptHard dependency on nodeDynamic loadStatic loadAnnotations based

injection-js

error No strict technical advantages over InversifyJS but the project seems less active and less popular (even though InversifyJS is not much active either)https://github.com/mgechev/injection-js

Community?

Extracted from Angular

MITlibraries.io
Latest release: Nov 7, 2020
Number of stars: 1.15k
Commits in the last 90 days: 1
yes acceptno accepterrorerroryes accept
InversifyJSaccept The project is in maintenance mode but still active and proved to be working well in our prototype.https://github.com/inversify/InversifyJSCommunityMITossrank/libraries.io
Latest release: Oct 14, 2021
Number of stars: 10.1k
Commits in the last 90 days: 9
yes acceptno acceptyes acceptyes accepterror not mandatory, the current PoC does not use annotations
TSyringecancel we tend to prefer community based developmenthttps://github.com/microsoft/tsyringeBacked by MicrosoftMITlibraries.io
Latest release: Jun 20, 2023
Number of stars: 4.17k
Commits in the last 90 days: 1
yes accepterrorerrorerrorerror
awilixcancel only support node environmenthttps://github.com/jeffijoe/awilixCommunityMITlibraries.io
Latest release: Oct 12, 2023
Number of stars: 3.07k
Commits in the last 90 days: 16
yes acceptyes cancelerrorerrorerror
typedicancel not active recentlyhttps://github.com/typestack/typedi?MITlibraries.io
Latest release: Jan 15, 2021
Number of stars: 3.38k
Commits in the last 90 days: a lot but only automatic dependency upgraded, will not be released
yes accepterrorerrorerroryes accept
diodcancel too small, not active recentlyhttps://github.com/artberri/diod?MITlibraries.io
Latest release: Nov 7, 2022
Number of stars: 64
     
mani-injectorcancel too small, not active recentlyhttps://github.com/jmankopf/mani-injector?MITlibraries.io
Latest release: May 1, 2022
Number of stars: 16
     
typescript-ioccancel too small, not active recentlyhttps://github.com/thiagobustamante/typescript-ioc?MITlibraries.io
Latest release: May 1, 2020
Number of stars: 440
     
bottlejserrorhttps://github.com/young-steveo/bottlejs?MITlibraries.io
Latest release: Jun 29, 2022
Number of stars: 1.26k
yes error to be tested?  no cancel
typed-injectcancel no support for annotationshttps://github.com/nicojs/typed-inject Apache 2.0libraries.io
Latest release: May 5, 2023
Number of stars: 335
yes accept?  no cancel

TODO: check the links of https://www.reddit.com/r/typescript/comments/y29103/are_there_any_browser_dependency_injection/

Get Connected