reactant-di
Version:
A dependency injection lib for Reactant
40 lines • 1.1 kB
TypeScript
import { ServiceIdentifier } from '../interfaces';
/**
* ## Description
*
* You can get a decorator `@lazy(serviceIdentifier)` with `getLazyDecorator((serviceIdentifier) => container.get(serviceIdentifier))`,
* and use it on any one dependency property that you need to lazily get.
*
* ## Example
*
* ```ts
* let container: Container;
* const lazy = getLazyDecorator((serviceIdentifier) =>
* container.get(serviceIdentifier)
* );
*
* @injectable()
* class Foo {
* public get test() {
* return 'test';
* }
* }
*
* @injectable()
* class Bar {
* @lazy('foo')
* foo?: Foo;
* }
*
* container = createContainer({
* ServiceIdentifiers: new Map(),
* });
*
* const bar = container.get(Bar);
*
* container.bind('foo').to(Foo);
* expect(bar.foo?.test).toBe('test');
* ```
*/
export declare const getLazyDecorator: (getService: (serviceIdentifier: ServiceIdentifier<unknown>, target?: object) => unknown) => (serviceIdentifier: ServiceIdentifier<unknown>, enableCache?: boolean) => (target: object, key: string | symbol) => any;
//# sourceMappingURL=lazy.d.ts.map