UNPKG

@adonisjs/fold

Version:

Simplest and straightforward implementation of IoC container in JavaScript

47 lines (46 loc) 1.57 kB
import type { AbstractConstructor, Constructor } from '@poppinss/utils/types'; import type { Container } from './container.ts'; import type { BindingResolver, Make } from './types.ts'; /** * A fluent builder to register contextual bindings with the * container. */ export declare class ContextBindingsBuilder<KnownBindings extends Record<any, any>, PinnedBinding extends AbstractConstructor<any>> { #private; /** * Initialize the contextual bindings builder * * @param parent - The parent class constructor for the contextual binding * @param container - The container instance to register bindings with */ constructor(parent: Constructor<any>, container: Container<KnownBindings>); /** * Specify the binding for which to register a custom * resolver. * * @param binding - The dependency class that the parent asks for * * @example * ```ts * container * .when(UsersController) * .asksFor(Hash) * .provide(() => new Argon2()) * ``` */ asksFor<Binding extends PinnedBinding>(binding: Binding): ContextBindingsBuilder<KnownBindings, Binding>; /** * Provide a resolver to resolve the parent dependency * * @param resolver - Factory function that returns the contextual implementation * * @example * ```ts * container * .when(UsersController) * .asksFor(Hash) * .provide(() => new Argon2()) * ``` */ provide(resolver: BindingResolver<KnownBindings, Make<PinnedBinding>>): void; }