import { IProviderClass , Type } from '../types' ; import { injected } from './injected' ; import { Injector , rootInjector } from '../core' ; export type TInjectableOptions = { isSingletonMode ? : boolean ; providedIn ? : Type < any > | 'root' | null ; injector ? : Injector ; } ; param { TInjectableOptions } options returns { ( _constructor : Function ) => void } export function Injectable ( options ? ) { return function ( _constructor ) : void { injected ( _constructor ) ; ( _constructor as any ) . isSingletonMode = true ; if ( options && options . isSingletonMode === false ) ( _constructor as any ) . isSingletonMode = false ; if ( options && options . providedIn && options . providedIn === 'root' ) rootInjector . setProvider ( _constructor , _constructor ) ; else if ( options && options . providedIn && ( options . providedIn as any ) . nvType === 'nvModule' ) { ( ( options . providedIn as any ) . prototype as IProviderClass ) . $providers . push ( { provide : _constructor , useClass : _constructor } ) ; } else if ( options && options . injector && options . injector instanceof Injector ) { options . injector . setProvider ( _constructor , _constructor ) ; } } ; }