@triviality/core
Version:
Purely typed service container
29 lines (28 loc) • 1.54 kB
TypeScript
/**
* Context for creating new service factories.
*/
import { ServiceFactory } from '../ServiceFactory';
import { TaggedServiceFactoryReference } from '../Value/TaggedServiceFactoryReference';
import { ServiceFunctionReferenceContainerInterface } from '../Container/ServiceFunctionReferenceContainerInterface';
export interface ReferenceContext {
/**
* Makes a service reference so they can be overridden or decorated when passed as return value
* to the service factory.
*
* @example
* const sf = ({reference}) => {
* const someService = reference(() => 'hi!');
* return {someService, otherService: () => someService() }
* }
*
* Now someService can be overridden, the service in otherService also overridden.
*/
reference<S>(sf: ServiceFactory<S>): ServiceFactory<S>;
}
export declare const SERVICE_REFERENCE: unique symbol;
export declare const asReference: <T>(sf: ServiceFactory<T>) => ServiceFactory<T>;
export declare const asMergeReference: <T>(reference: () => TaggedServiceFactoryReference) => ServiceFactory<T>;
export declare const isServiceReferenced: (factory: any) => boolean;
export declare const handleServiceReferenced: <T>(builder: ServiceFunctionReferenceContainerInterface<any>, factory: ServiceFactory<T>, tag: string) => ServiceFactory<T>;
export declare const wrapReturnAsReference: <T extends ((...args: any[]) => ServiceFactory<any>)>(toWrap: T) => T;
export declare const createServiceFactoryReferenceContext: () => ReferenceContext;