redi
redi (pronounced 'ready') is a dependency injection library for TypeScript (and JavaScript), along with a set of bindings for React.
💡
Write code that is less coupling, more convenient to modify and easier to maintain with help of dependency injection.
Overview
import { Inject } from '@wendellhu/redi'class AuthService { public getCurrentUserInfo(): UserInfo { // your implementation here... }}class FileListService { constructor(@Inject(AuthService) private readonly authService: AuthService) {} public getUserFiles(): Promise<Files> { const currentUser = this.authService.getCurrentUserInfo() // ... }}const injector = new Injector([[AuthService], [FileListService]])injector.get(AuthService)
Features
- Completely opt-in. Unlike Angular, redi does not force you to use dependency injection in your whole applocation. You can use wherever you like.
- Supports multi kinds of dependency items, including classes, JavaScript primitive values and objects, factory functions and async items.
- Supports n-ary dependency injection.
- Supports hierarchy dependency injection system.
- Supports lazy instantiation.