resolvd
Simple, small, and type-safe inversion of control/dependency injection for JavaScript & TypeScript with zero dependencies
Upgrading from 1.x -> 2.x
Version 2 is fully promise based, but the only change that's necessary is await
ing the result of ioc().resolve
:
; ; // throws:// There are circular dependencies in your service definitions:// * b -> a -> c -> bawait container.resolve;
Circular dependencies
resolvd will identify circular dependencies and throw an error message containing the offending services:
; // A requires B, which requires C, which requires A, which requires B, etc.;;; ; // throws:// There are circular dependencies in your service definitions:// * b -> a -> c -> bcontainer.resolve;
Type-safe
Trying to define a dependency of the wrong type will cause an TypeScript error - stopping the issue at compile time
Usage
; ; ; ; // create a new container with the specified services available;// resolve the service definitions into an object of type `PublicServices`; // the PublicServices are now available!services.logger.log'hello, world!'; // [2020-06-10T19:26:34.000Z] hello, world!
Services should only be registered using ioc().define(...)
!