import { BindingKey , Context , inject , Injection , ResolutionSession , ResolverFunction , } from '@loopback/context' ; param ctx param injection param session const resolve = ( ctx , injection , session ) => { console . log ( 'Context: %s Binding: %s' , ctx . name , session . currentBinding ! . key ) ; const targetName = ResolutionSession . describeInjection ( injection ) . targetName ; console . log ( 'Injection: %s' , targetName ) ; return injection . member === 'prefix' ? new Date ( ) . toISOString ( ) : 'John' ; } ; /**
 * A class with dependency injection
 */ class Greeter { constructor ( @ inject ( '' , { } , resolve ) private name ) { } @ inject ( '' , { } , resolve ) prefix = '' ; hello ( ) { return `[${ this . prefix }] Hello, ${ this . name }` ; } } const GREETER = BindingKey . create < Greeter > ( 'greeter' ) ; export async function main ( ) { const ctx = new Context ( 'invocation-context' ) ; ctx . bind ( GREETER ) . toClass ( Greeter ) ; const greeter = await ctx . get ( GREETER ) ; console . log ( greeter . hello ( ) ) ; } if ( require . main === module ) { main ( ) . catch ( err => { console . error ( err ) ; process . exit ( 1 ) ; } ) ; }