UNPKG

contexify

Version:

A TypeScript library providing a powerful dependency injection container with context-based IoC capabilities, inspired by LoopBack's Context system.

55 lines (50 loc) 2.57 kB
import { z as Context, _ as ResolutionSession } from '../index-CSgk2Bzc.js'; import { Constructor, ValueOrPromise, BoundValue, MapObject } from '../utils/value-promise.js'; import 'events'; import '../provider/provider.js'; import '../binding/binding-key.js'; import 'metarize'; import '../utils/json-types.js'; import '../utils/debug.js'; /** * Create an instance of a class which constructor has arguments * decorated with `@inject`. * * The function returns a class when all dependencies were * resolved synchronously, or a Promise otherwise. * * @param ctor - The class constructor to call. * @param ctx - The context containing values for `@inject` resolution * @param session - Optional session for binding and dependency resolution * @param nonInjectedArgs - Optional array of args for non-injected parameters */ declare function instantiateClass<T extends object>(ctor: Constructor<T>, ctx: Context, session?: ResolutionSession, nonInjectedArgs?: any[]): ValueOrPromise<T>; /** * Given a function with arguments decorated with `@inject`, * return the list of arguments resolved using the values * bound in `ctx`. * The function returns an argument array when all dependencies were * resolved synchronously, or a Promise otherwise. * * @param target - The class for constructor injection or prototype for method * injection * @param method - The method name. If set to '', the constructor will * be used. * @param ctx - The context containing values for `@inject` resolution * @param session - Optional session for binding and dependency resolution * @param nonInjectedArgs - Optional array of args for non-injected parameters */ declare function resolveInjectedArguments(target: object, method: string, ctx: Context, session?: ResolutionSession, nonInjectedArgs?: any[]): ValueOrPromise<BoundValue[]>; /** * Given a class with properties decorated with `@inject`, * return the map of properties resolved using the values * bound in `ctx`. * The function returns an argument array when all dependencies were * resolved synchronously, or a Promise otherwise. * * @param constructor - The class for which properties should be resolved. * @param ctx - The context containing values for `@inject` resolution * @param session - Optional session for binding and dependency resolution */ declare function resolveInjectedProperties(constructor: Constructor<unknown>, ctx: Context, session?: ResolutionSession): ValueOrPromise<MapObject<BoundValue>>; export { instantiateClass, resolveInjectedArguments, resolveInjectedProperties };