UNPKG

2.5 kBTypeScriptView Raw
1import { Binding, BindingFilter, BindingFromClassOptions, BindingTemplate, InjectionMetadata } from '@loopback/context';
2import { ServiceOrProviderClass } from './application';
3/**
4 * Representing an interface for services. In TypeScript, the `interface` does
5 * not have reflections at runtime. We use a string, a symbol or a Function as
6 * the type for the service interface.
7 */
8export type ServiceInterface = string | symbol | Function;
9/**
10 * Options to register a service binding
11 */
12export interface ServiceOptions extends BindingFromClassOptions {
13 interface?: ServiceInterface;
14}
15/**
16 * `@service` injects a service instance that matches the class or interface.
17 *
18 * @param serviceInterface - Interface for the service. It can be in one of the
19 * following forms:
20 *
21 * - A class, such as MyService
22 * - A string that identifies the interface, such as `'MyService'`
23 * - A symbol that identifies the interface, such as `Symbol('MyService')`
24 *
25 * If not provided, the value is inferred from the design:type of the parameter
26 * or property
27 *
28 * @example
29 * ```ts
30 *
31 * const ctx = new Context();
32 * ctx.bind('my-service').toClass(MyService);
33 * ctx.bind('logger').toClass(Logger);
34 *
35 * export class MyController {
36 * constructor(@service(MyService) private myService: MyService) {}
37 *
38 * @service()
39 * private logger: Logger;
40 * }
41 *
42 * ctx.bind('my-controller').toClass(MyController);
43 * await myController = ctx.get<MyController>('my-controller');
44 * ```
45 */
46export declare function service(serviceInterface?: ServiceInterface, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
47/**
48 * Create a binding filter by service class
49 * @param serviceInterface - Service class matching the one used by `binding.toClass()`
50 * @param options - Options to control if subclasses should be skipped for matching
51 */
52export declare function filterByServiceInterface(serviceInterface: ServiceInterface): BindingFilter;
53/**
54 * Create a service binding from a class or provider
55 * @param cls - Service class or provider
56 * @param options - Service options
57 */
58export declare function createServiceBinding<S>(cls: ServiceOrProviderClass<S>, options?: ServiceOptions): Binding<S>;
59/**
60 * Create a binding template for a service interface
61 * @param serviceInterface - Service interface
62 */
63export declare function asService(serviceInterface: ServiceInterface): BindingTemplate;
64
\No newline at end of file