Livshitz

Entrepreneur & Engineerā€™s Journey

Follow publication

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 šŸ™.

Sign up to discover human stories that deepen your understanding of the world.

Livshitz
Livshitz

Published in Livshitz

Entrepreneur & Engineerā€™s Journey

Elya Livshitz
Elya Livshitz

Written by Elya Livshitz

Passionate technologist with over a decade experience, eager to learn new technologies, challenges-killer and out-of-the-box thinker. zuz.to/liv

No responses yet

Write a response