import { BindingKey , Context , inject , instantiateClass } from '@loopback/context' ; /**
 * Strongly-typed binding key for the current user
 */ const CURRENT_USER = BindingKey . create < string > ( 'currentUser' ) ; /**
 * A class with dependency injection
 */ class Greeter { constructor ( @ inject ( CURRENT_USER ) private userName ) { } hello ( ) { return `Hello, ${ this . userName }` ; } } param ctx async function sayHello ( ctx ) { const greeter = await instantiateClass ( Greeter , ctx ) ; console . log ( greeter . hello ( ) ) ; } export async function main ( ) { const ctx = new Context ( 'invocation-context' ) ; ctx . bind ( CURRENT_USER ) . to ( 'John' ) ; await sayHello ( ctx ) ; } if ( require . main === module ) { main ( ) . catch ( err => { console . error ( err ) ; process . exit ( 1 ) ; } ) ; }