Skip to content

Dependency Injection

Requires TypeScript 5.4 or newer.

Terminal window
npm i udic

Import:

import * as di from 'udic';
// Named imports
import {
service, use, inject,
impl, link
} from 'udic';
// Type imports
import type {
Service, Compute, Impl
TResult, TDependency
} from 'udic';
  • <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.

  • <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.