@eclipse-scout/core
Version:
Eclipse Scout runtime
58 lines • 2.77 kB
TypeScript
import { Constructor, ObjectType } from '../index';
/**
* Represents an ordered collection of instances of the specified object type. These are created automatically
* on first access and are stored in the registry indefinitely or until explicitly unregistered.
*
* The object registry can be used as an extension point for other application modules. It allows callers
* to apply the _inversion of control_ principle, similar to `BEANS.all()` in Java.
*
* @template TObject The type of objects managed by this registry.
*/
export declare class ObjectRegistry<TObject extends object> {
static readonly DEFAULT_ORDER = 5000;
protected readonly _registrations: ObjectRegistration<TObject>[];
/**
* Registers the given object type with this registry. After registration, the list returned by {@link all}
* will include an instance of this type in the order it was registered. The object instance ise created
* using {@link scout.create}. The default ordering can be altered by specifying an explicit order. The
* default order is {@link DEFAULT_ORDER}.
*
* @returns An object that can be used to {@link unregister} the object again.
*/
register(objectType: Constructor<TObject>, options?: number | ObjectRegistryRegisterOptions): ObjectRegistration<TObject>;
protected _prepareOptions(options?: number | ObjectRegistryRegisterOptions): ObjectRegistryRegisterOptions;
protected _createRegistration<T>(objectType: Constructor<TObject>, options: ObjectRegistryRegisterOptions): ObjectRegistration<TObject>;
/**
* Unregisters a previously registered object.
*
* @param registration The registration handle that was returned by {@link register}.
* @return true if the registration was removed, false otherwise.
*/
unregister(registration: ObjectRegistration<TObject>): boolean;
/**
* @returns All registered objects in the order specified during registration.
*/
all(): TObject[];
}
export interface ObjectRegistryRegisterOptions {
/**
* Default is {@link ObjectRegistry.DEFAULT_ORDER}.
*/
order?: number;
}
/**
* Registration handle of an object in an {@link ObjectFactory}. Can be used to unregister the object again.
*/
export interface ObjectRegistration<TObject extends object> {
objectType: ObjectType<TObject>;
instance: TObject;
order: number;
}
export declare class ObjectRegistries {
protected static readonly _INSTANCES: Map<Constructor<any>, ObjectRegistry<any>>;
/**
* @returns a singleton instance of the given {@link ObjectFactory} class.
*/
static get<TRegistry extends ObjectRegistry<any>>(registryType: Constructor<TRegistry>): TRegistry;
}
//# sourceMappingURL=ObjectRegistry.d.ts.map