@kephas/core
Version:
Provides a common infrastructure for all the other Kephas Framework components: ambient services, dynamic reflection, composition, application management, and others.
97 lines (96 loc) • 3.13 kB
TypeScript
import { Expando } from "../expando";
import { AbstractType } from "../type";
import { AppServiceMetadata } from "./appServiceMetadata";
/**
* Enumerates the lifetime values for application services.
*
* @export
* @enum {number}
*/
export declare enum AppServiceLifetime {
/**
* The application service is shared (default).
*/
Singleton = 0,
/**
* The application service in instantiated with every request.
*/
Transient = 1,
/**
* The application service is shared within a scope.
*/
Scoped = 2
}
/**
* Provides information about the application service.
*
* @export
* @class AppServiceInfo
*/
export declare class AppServiceInfo implements Expando {
/**
* Gets a value indicating whether multiple services for this contract are allowed.
*
* @type {boolean}
* @memberof AppServiceInfo
*/
readonly allowMultiple: boolean;
/**
* Gets the application service lifetime.
*
* @type {AppServiceLifetime}
* @memberof AppServiceInfo
*/
readonly lifetime: AppServiceLifetime;
/**
* Gets the contract type of the service.
*
* @type {AbstractType}
* @memberof AppServiceInfo
*/
readonly contractType: AbstractType;
/**
* Gets the contract token of the service.
*
* @type {*}
* @memberof AppServiceInfo
*/
readonly contractToken: any;
/**
* Gets an iteration of registered services.
*
* @readonly
* @type {IterableIterator<AppServiceMetadata>}
* @memberof AppServiceInfo
*/
get services(): IterableIterator<AppServiceMetadata<any>>;
private _services;
/**
* Creates an instance of AppServiceInfo.
* @param {Type<T>} contractType The contract type.
* @param {*} contractToken The contract token.
* @param {boolean} [allowMultiple=false] Indicates whether multiple instances of the provided
* @param {AppServiceLifetime} [lifetime=AppServiceLifetime.Singleton] The application service lifetime.
* @memberof AppServiceInfo
*/
constructor({ contractType, contractToken, allowMultiple, lifetime, ...args }: {
contractType: AbstractType;
contractToken?: any;
allowMultiple?: boolean;
lifetime?: AppServiceLifetime;
[key: string]: any;
});
/**
* Registers a service implementation for this contract.
*
* @template T The service implementation type.
* @param {AppServiceMetadata<T>} service
* @returns {(boolean | ServiceError | AppServiceMetadata<any>)}
* True, if the service was registered successfully.
* False, if the service was not registered due to a higher override priority service already registered.
* ServiceError, if a service is already registered with the same override priority.
* AppServiceMetadata<any>, if the service to register overrid an existing one. The overridden service is returned.
* @memberof AppServiceInfo
*/
private registerService;
}