import { Container } from "./container" ; interface AnyObject { [ prop ] : any ; } export const NOCACHE = Symbol ( "NOCACHE" ) ; function define < T extends AnyObject > ( target , property , container , type , args ) { Object . defineProperty ( target , property , { get : function ( ) { const value = container . get < any > ( type ) ; if ( args . indexOf ( NOCACHE ) === - 1 ) { Object . defineProperty ( this , property , { value , enumerable : true , } ) ; } return value ; } , configurable : true , enumerable : true , } ) ; } function inject ( type , container , args ) { return < T extends AnyObject > ( target , property ) : void => { define ( target , property , container , type , args ) ; } ; } export function createDecorator ( container ) { return ( type , ... args ) => { return inject ( type , container , args ) ; } ; } export function createWire ( container ) { return < T extends AnyObject > ( target , property , type , ... args ) => { define ( target , property , container , type , args ) ; } ; } export function createResolve ( container ) { return < T = never > ( type , ... args ) => { let value ; return ( ) : T => { if ( args . indexOf ( NOCACHE ) !== - 1 || value === undefined ) { value = container . get < T > ( type ) ; } return value ; } ; } ; }