import { ProviderNotRegisteredException } from '../exception' ; import type { LoggableInterface , LoggerInterface } from '../logger' ; import type { Constructor } from '../types' ; import type { AbstractProvider } from './abstract-provider' ; import type { ProvidableInterface } from './providable.interface' ; export function ProvidableMixin < TBase extends Constructor < LoggableInterface > > ( Base ) { return class extends Base { private readonly providers : AbstractProvider [ ] = [ ] ; constructor ( ... args ) { super ( ) ; const [ providers ] = args as any ; if ( ! providers . length ) { throw ProviderNotRegisteredException . noProviderRegistered ( ) ; } this . registerProviders ( providers ) ; } getFirstProvider ( ) { return this . getProviders ( ) [ 0 ] ; } getProviders ( ) { return this . providers ; } registerProvider ( provider ) { this . providers . push ( provider ) ; return this ; } registerProviders ( providers ) { for ( const provider of providers ) { this . registerProvider ( provider ) ; } return this ; } setLogger ( logger ) { super . setLogger ( logger ) ; for ( const provider of this . getProviders ( ) ) { provider . setLogger ( logger ) ; } return this ; } } ; }