import { BindingAddress , BindingTag , Constructor , Context , createBindingFromClass , inject , injectable , } from '@loopback/context' ; /**
 * Interface for `Greeter`
 */ interface Greeter { hello ( ) : string ; } param bindingKeyForName param tags function createClassWithDecoration ( bindingKeyForName , ... tags ) { @ injectable ( { tags } ) class GreeterTemplate implements Greeter { constructor ( @ inject ( bindingKeyForName ) private userName ) { } hello ( ) { return `Hello, ${ this . userName }` ; } } return GreeterTemplate ; } export async function main ( ) { const ctx = new Context ( ) ; ctx . bind ( 'name1' ) . to ( 'John' ) ; ctx . bind ( 'name2' ) . to ( 'Jane' ) ; const class1 = createClassWithDecoration ( 'name1' , { tags : { prefix : '1' } } ) ; const binding1 = createBindingFromClass ( class1 , { key : 'greeter1' } ) ; ctx . add ( binding1 ) ; console . log ( '1:' , binding1 . tagMap ) ; const class2 = createClassWithDecoration ( 'name2' , { tags : { prefix : '2' } } ) ; const binding2 = createBindingFromClass ( class2 , { key : 'greeter2' } ) ; ctx . add ( binding2 ) ; console . log ( '2:' , binding2 . tagMap ) ; const greeting1 = await ctx . get < Greeter > ( 'greeter1' ) ; console . log ( '1: %s' , greeting1 . hello ( ) ) ; const greeting2 = await ctx . get < Greeter > ( 'greeter2' ) ; console . log ( '2: %s' , greeting2 . hello ( ) ) ; } if ( require . main === module ) { main ( ) . catch ( err => { console . error ( err ) ; process . exit ( 1 ) ; } ) ; }