Dependency Injection
Requires TypeScript 5.4 or newer.
npm i udicbun i udicpnpm i udicyarn add udicGuides
Section titled “Guides” Using Services Create and use services.
Provide implementations Provide implementations for computes.
Import:
import * as di from 'udic';
// Named importsimport { service, use, inject, impl, link} from 'udic';
// Type importsimport type { Service, Compute, Impl TResult, TDependency} from 'udic';service()
Section titled “service()”<T>- Service identifier type.name: T- Service identifier.- Returns
<K>() => di.Service<T, K>
Create a service.
<const T>- Compute dependency list type.<const R>- Compute result type.deps: T- Compute dependency list.f: (...args: ...) => R- The function to compute the result from provided dependencies.- Returns
di.Compute<...>- A function that requires the implementations of the provided dependencies to execute.
Create a compute that requires the specified dependencies to run.
inject()
Section titled “inject()”<T>- Input compute dependencies type.<R>- Input compute result type.<D>- Provided dependencies type.compute: di.Compute<T, R>- Target compute to inject dependencies.deps: D- Dependencies to inject to the compute.- Returns
di.Compute<...>
Create a new compute with provided dependencies.