Purely-functional strictly-typed IoC/DI for TypeScript.
This project aims at providing lightweight inversion of control (IoC) and dependency injection (DI) tooling for large JavaScript/TypeScript applications.
While the concepts of IoC and DI are not new and there are multiple implementations of them available for JavaScript and TypeScript, most of them are built around the concept of a single container with all registered dependencies (or multiple containers).
While such approach might work for some projects, it still introduces tight coupling in the code. We have to either manually register all dependencies in such container (which can be quite tedious), or delegate it to a framework which will register them automatically on a single global container which makes the code not portable.
While the issues above might seem synthetic, there's still another major downside of such approach - there is no way to statically check whether all required dependencies are actually registered on the container. If any of requested dependencies is missing, container throws in runtime which makes the code impure and indeterminate.
So, the goals of this project are to:
- provide a purely-functional solution for automatic IoC/DI
- provide compile-time guarantees that all required dependencies are always available for the caller.
- 🤝 - strictly typed, your code can finally be trusted
- λ - purely functional, your code is determinate, composable, without side-effects
- 👻 - transparent, your code requires no additional infrastructure like containers and frameworks, it just works
- ⚡️ - efficient, your code is cached and only runs when its dependencies change
- ⚛️ - React integration, your code can be seamlessly integrated into any React application
The project is split into several packages, and you can find documentation for them in the corresponding readme files.
- @injectable-ts/core - the main package containing building blocks for the IoC/DI (see docs)
- @injectable-ts/react - bindings for React for better integration with the core (see docs)
- more coming soon
Read more here
This repository is powered by nx.
This means that subpackages are built into a single directory /dist
.
This repository uses lerna ONLY for bumping versions until it's supported natively by nx.
Make sure NOT to call lerna bootstrap
and other commands.
lerna version <version>
Then
npm run deploy