Repository navigation
Expand file tree
/
Copy pathservice.ts
More file actions
82 lines (74 loc) · 2.13 KB
/
Copy pathservice.ts
File metadata and controls
82 lines (74 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {AbstractType, Type} from '../interface/type';
import {makeDecorator, TypeDecorator} from '../util/decorators';
import {compileService} from './jit/service';
/**
* Type of the Service decorator / constructor function.
*
* @publicApi
*/
export interface ServiceDecorator {
/**
* Decorator that marks a class as a service and makes it automatically available
* in the dependency injection system.
*
* @see [Introduction to Services and DI](guide/di)
* @see [Creating and using services](guide/di/creating-and-using-services)
* @see [Defining dependency providers](guide/di/defining-dependency-providers)
*/
(): TypeDecorator;
/**
* When `autoProvided` is set to `false`, the service won't be exposed to the dependency
* injection system automatically. It is up to the user to expose it in a providers list.
*/
(options: {autoProvided: false}): TypeDecorator;
/**
* Creates a service that is automatically provided and uses
* the value returned from the `factory` function.
*/
<T>(options: {
autoProvided?: true;
factory: () => T;
}): <C extends Type<unknown> | AbstractType<unknown>>(
target: C,
) => C extends Type<unknown> ? Type<T> : abstract new (...args: any[]) => T;
/**
* Creates a service that is automatically provided.
*/
(options?: {autoProvided?: true}): TypeDecorator;
}
/**
* Type of the Service metadata.
*
* @publicApi
*/
export interface Service {
/**
* Determines whether the service should be provided automatically or by the user.
* Defaults to `true`.
*/
autoProvided?: boolean;
/**
* A function to invoke to create a value for this service.
*/
factory?: () => unknown;
}
/**
* Service decorator and metadata.
*
* @Annotation
* @publicApi
*/
export const Service: ServiceDecorator = makeDecorator(
'Service',
undefined,
undefined,
undefined,
(type: Type<unknown>, meta: Service | undefined) => compileService(type, meta),
);