@furystack/inject
Version:
Dependency Injection framework for FuryStack
29 lines • 1.23 kB
TypeScript
import type { DefineServiceAsyncOptions, DefineServiceOptions, Lifetime, Token } from './types.js';
/**
* Defines a sync service and returns a {@link Token} resolvable via
* {@link Injector.get}.
*
* @example
* ```ts
* const Counter = defineService({
* name: 'my-app/Counter',
* lifetime: 'singleton',
* factory: () => {
* let value = 0
* return { increment: () => ++value, getValue: () => value }
* },
* })
* ```
*/
export declare const defineService: <TService, TLifetime extends Lifetime>(options: DefineServiceOptions<TService, TLifetime>) => Token<TService, TLifetime, false>;
/**
* Async counterpart of {@link defineService}. The returned token can only be
* resolved via {@link Injector.getAsync} — {@link Injector.get} rejects async
* tokens at compile time.
*
* Resolved values are cached after first resolution; concurrent callers share
* the same pending promise.
*/
export declare const defineServiceAsync: <TService, TLifetime extends Lifetime>(options: DefineServiceAsyncOptions<TService, TLifetime>) => Token<TService, TLifetime, true>;
export declare const isToken: <TService = unknown>(value: unknown) => value is Token<TService>;
//# sourceMappingURL=define-service.d.ts.map