/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/core/src/di/service.ts
82 строки
2 KB
Kristiyan Kostadinov
fix(core): allow service with factory on abstract classes
08 май 2026, 11:16
08 май 2026, 11:16
c72ebcb
Код
Авторство
О чём код?
/** * @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), );