* Register a life cycle observer class * @param ctor - A class implements LifeCycleObserver * @param nameOrOptions - Optional name or options for the life cycle observer
(
ctor: Constructor<T>,
nameOrOptions?: string | BindingFromClassOptions,
)
| 501 | * @param nameOrOptions - Optional name or options for the life cycle observer |
| 502 | */ |
| 503 | public lifeCycleObserver<T extends LifeCycleObserver>( |
| 504 | ctor: Constructor<T>, |
| 505 | nameOrOptions?: string | BindingFromClassOptions, |
| 506 | ): Binding<T> { |
| 507 | this.debug('Adding life cycle observer %s', nameOrOptions ?? ctor.name); |
| 508 | const binding = createBindingFromClass(ctor, { |
| 509 | namespace: CoreBindings.LIFE_CYCLE_OBSERVERS, |
| 510 | type: CoreTags.LIFE_CYCLE_OBSERVER, |
| 511 | defaultScope: BindingScope.SINGLETON, |
| 512 | ...toOptions(nameOrOptions), |
| 513 | }).apply(asLifeCycleObserver); |
| 514 | this.add(binding); |
| 515 | return binding; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Add a service to this application. |