reverse initialization order, prepare for publishing
This commit is contained in:
@@ -9,6 +9,7 @@ export function Singleton(config?: {
|
||||
interface?: Constructor<any>,
|
||||
initializationPriority?: number
|
||||
}): GenericClassDecorator<Type<any>> {
|
||||
|
||||
return (clazz: Type<any>) => {
|
||||
Injector['singletonDefinitions'].push({
|
||||
initializationPriority: config ?. initializationPriority,
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import 'reflect-metadata';
|
||||
import { ERR_NO_INITIALIZE_WITH_PRIORITY, ERR_NO_INJECTION_TOKEN } from './Strings';
|
||||
import { Constructor, Type, Module as SingletonDefinition, InjectionError, InjectionResolutionError } from './Internals';
|
||||
import { Constructor, Type, SingletonDefinition, InjectionError, InjectionResolutionError } from './Internals';
|
||||
|
||||
class _Injector {
|
||||
|
||||
@@ -71,7 +71,7 @@ class _Injector {
|
||||
|
||||
private initializeSingletons = () => {
|
||||
this.singletonDefinitions
|
||||
.sort((a, b) => (a.initializationPriority ?? 0) - (b.initializationPriority ?? 0))
|
||||
.sort((a, b) => (b.initializationPriority ?? 0) - (a.initializationPriority ?? 0))
|
||||
.map(def => this.singletonObjects[def.ctor.name])
|
||||
.forEach(obj => obj.initialize ? obj.initialize() : undefined)
|
||||
}
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ export type Constructor<T> = Function & { prototype: T }
|
||||
*/
|
||||
export type GenericClassDecorator<T> = (target: T) => void;
|
||||
|
||||
export type Module = {
|
||||
initializationPriority?: number //Priority of initializing this object after creation
|
||||
export type SingletonDefinition = {
|
||||
initializationPriority?: number //Priority of initializing this object after creation, lower value means higher priority; default: 0
|
||||
ctor: Type<any> //Object constructor to make singleton from
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user