PumpIt is a small (~2KB) dependency injection container without the decorators and zero dependencies, suitable for the browser. It supports different

Search code, repositories, users, issues, pull requests...

submited by
Style Pass
2024-10-23 21:30:04

PumpIt is a small (~2KB) dependency injection container without the decorators and zero dependencies, suitable for the browser. It supports different injection scopes, child containers, hooks etc...

Dependency injection is a powerful concept, and there are some excellent solutions like tsyringe, awilix, and inversify, however, they all use decorators (which are great, but not a standard), and their file size is not suitable for front-end development. So I've decided to create an implementation of a dependency injection container that is small and doesn't use decorators. I also believe that I've covered all the functionality of the above-mentioned libraries.

Since PumpIt does not rely on the decorators the injection is done via the injection property. When used with classes, inject will be a static property on the class, and it will hold an array of registered injection tokens that will be injected into the constructor in the same order when the class instance is created (in case of factory functions it will be a property on the function itself, more on that later).

There is also alternative syntax that you can use when you don't want to use the static inject property, or you are importing a class from third-party packages.

Leave a Comment