import { Status, isStatus } from '../const/status.ts' import { Collection } from '../collection/Collection.ts' import {container, make} from '../../../di/src/global.ts' import {DependencyKey} from '../../../di/src/type/DependencyKey.ts' import Instantiable, {isInstantiable} from '../../../di/src/type/Instantiable.ts' import AppClass from './AppClass.ts' const isLifecycleUnit = (something: any): something is (typeof LifecycleUnit) => { return isInstantiable(something) && something.prototype instanceof LifecycleUnit } export default abstract class LifecycleUnit extends AppClass { private _status = Status.Stopped public get status() { return this._status } public set status(status) { this._status = status } public async up(): Promise {}; public async down(): Promise {}; public static get_dependencies(): Collection { if ( isInstantiable(this) ) { const deps = new Collection() for ( const dependency of container.get_dependencies(this) ) { if ( isLifecycleUnit(dependency) ) deps.push(dependency) } return deps } return new Collection() } }