Introducing my new Dependency Injection Container for TS/JS projects
š di.libx.js
Source in Github: link
yarn add di.libx.js
Lightweight Dependency Injection module that supports async/deferred resolution and uglified support for Typescript and JavaScript in 3.3kB gzipped (14.7kB on disk). Feature complete, fast, reliable and well tested.
Why:
Almost every TS/JS project has singleton instances floating around. When those singletons have dependencies on other singletons that can easily become a mess.
Following āClean Codeā guidelines, one should invest into Dependency Inversion (aka Inversion of Control, Dependency Injection),
di.libx.js offers straightforward and explicit approach to register dependencies and design other moduleās dependencies in efficient and agnostic way. Supporting async/awaitable resolution making it perfect fit into modern web apps as well to NodeJS backends.
Compared to other existing libraries such as injection-js, which requires intrusive modification of your code with Typescript attributes, or require-js that is being a overwhelming comprehensive module-system, di.libx.js is aiming to be a simple DI container to manage, organize and orchestrate modules.
di.libx.js is intended to create a dead simple yet flexible DI container that could let you express dependencies in declarative and explicit way, not get into your way by forcing annotations and allow progressive resolution (lazy-downloaded dependencies).
Features:
- Deferred resolution ā asynchronously require dependencies that are not yet available and resolve once it is.
- Automatic resolve of function params ā resolve & map dependencies manually or as functionās parameters
- NodeJS & browser ā browserified version ready to use from CDN.
- Explicit or implicit dependencies ā works with uglified files by specified dependenciesā names or implicitly from function/class name.
- Typescript support ā specify injected instanceās types.
How to use and more examples:
see more here.
Share your ā¤ļø, tick āļø in the repo š.