Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/lambda_ioc/lambda-ioc/deno/container.ts>WritableContainer

Super type safe dependency injection ๐Ÿ’‰ for TypeScript (inspired by Diddly)
Latest
interface WritableContainer
import { type WritableContainer } from "https://deno.land/x/lambda_ioc@1.0.0/lambda-ioc/deno/container.ts";

Represents a write-only version of a type-safe IoC container with "auto-wired" dependencies resolution.

Type Parameters

TSyncDependencies extends Record<ConstrainedKey, unknown>
TAsyncDependencies extends Record<ConstrainedKey, unknown>

Methods

register<TName extends ConstrainedKey, TDependency extends TName extends keyof TSyncDependencies ? TSyncDependencies[TName] : TName extends "$" | keyof TAsyncDependencies ? never : unknown>(name: TName, dependency: SyncDependencyFactory<TDependency, ReadableSyncContainer<TSyncDependencies>>): Container<[TK in keyof TSyncDependencies | TName]: TK extends keyof TSyncDependencies ? TName extends TK ? TDependency : TSyncDependencies[TK] : TDependency, TAsyncDependencies>

Registers a new synchronous dependency factory. It cannot be used when self-resolution is needed. Use registerConstructor instead.

registerAsync<TName extends ConstrainedKey, TDependency extends TName extends "$" | keyof TSyncDependencies ? never : TName extends keyof TAsyncDependencies ? TAsyncDependencies[TName] : unknown>(name: TName, dependency: AsyncDependencyFactory<TDependency, ReadableContainer<TSyncDependencies, TAsyncDependencies>>): Container<TSyncDependencies, [TK in keyof TAsyncDependencies | TName]: TK extends keyof TAsyncDependencies ? TName extends TK ? TDependency : TAsyncDependencies[TK] : TDependency>

Registers a new asynchronous dependency factory. It cannot be used when self-resolution is needed. Use registerAsyncConstructor instead.

registerConstructor<TName extends ConstrainedKey, TParams extends ()[], TClass extends TName extends "$" | keyof TAsyncDependencies ? never : TName extends keyof TSyncDependencies ? TSyncDependencies[TName] : unknown, TDependencies extends ContextualParamsToSyncResolverKeys<TSyncDependencies, TAsyncDependencies, TParams>>(
name: TName,
constructor: new (...args: TParams) => TClass,
...args: TDependencies,
): Container<[TK in keyof TSyncDependencies | TName]: TK extends keyof TSyncDependencies ? TName extends TK ? TClass : TSyncDependencies[TK] : TClass, TAsyncDependencies>
registerAsyncConstructor<TName extends ConstrainedKey, TParams extends ()[], TClass extends TName extends "$" | keyof TSyncDependencies ? never : TName extends keyof TAsyncDependencies ? TAsyncDependencies[TName] : unknown, TDependencies extends ContextualParamsToAsyncResolverKeys<TSyncDependencies, TAsyncDependencies, TParams>>(
name: TName,
constructor: new (...args: TParams) => TClass,
...args: TDependencies,
): Container<TSyncDependencies, [TK in keyof TAsyncDependencies | TName]: TK extends keyof TAsyncDependencies ? TName extends TK ? TClass : TAsyncDependencies[TK] : TClass>

Registers a new constructor that might have asynchronous-resolvable dependencies. This method is helpful when the constructor combinator is not powerful enough (as it's only able to resolve synchronously, and it cannot take advantage of self-resolution either).

registerValue<TName extends ConstrainedKey, TDependency extends TName extends keyof TSyncDependencies ? TSyncDependencies[TName] : TName extends "$" | keyof TAsyncDependencies ? never : unknown>(name: TName, dependency: TDependency): Container<[TK in keyof TSyncDependencies | TName]: TK extends keyof TSyncDependencies ? TName extends TK ? TDependency : TSyncDependencies[TK] : TDependency, TAsyncDependencies>

Registers an already instantiated dependency.