checked-inject: Statically Verified Dependency Injection for TypeScript
checked-inject is a TypeScript library that provides dependency injection with compile-time verification. The library allows developers to represent the entire dependency graph in the type system and enforce it statically when requesting a resource from the DI container. This ensures that all dependencies are provided correctly and eliminates runtime errors.
With checked-inject, developers can declare multiple dependencies in a provider by structuring keys into arrays or objects. The library also provides dependency operators such as Lazy and Provider, which evaluate to functions that provide the requested type. Lazy caches the output after the first invocation, while Provider creates a new instance for each invocation. Additionally, the Async operator allows requesting async dependencies without the need for additional functions.
checked-inject also supports scoping to manage the lifecycle of resolved resources. By binding a resource to one or more scopes, its instance can be reused as long as the scopes are valid. The library includes the Singleton scope, which ensures that a resource is only resolved once per container.
Overall, checked-inject offers a powerful and type-safe approach to dependency injection in TypeScript. Developers can find more detailed information and usage examples in the library's README.