import { getType } from "tst-reflect" ; import { ServiceCollection } from "./ServiceCollection" ; import { ServiceProvider } from "./ServiceProvider" ; interface ILog { log ( ... args ) ; } class Log implements ILog { log ( ... args ) { console . log . apply ( undefined , args ) ; } } interface IService { doJob ( number ) ; } class Service implements IService { private log : ILog ; constructor ( log ) { this . log = log ; } doJob ( number ) { const job = number + number ; this . log . log ( `${ number } + ${ number } = ${ job }` ) ; } } const serviceCollection = new ServiceCollection ( ) ; serviceCollection . addTransient ( getType < ILog > ( ) , getType < Log > ( ) ) ; serviceCollection . addTransient < IService , Service > ( ) ; const serviceProvider = new ServiceProvider ( serviceCollection ) ; const logger = serviceProvider . getService < ILog > ( ) ; const service = serviceProvider . getService < IService > ( ) ; logger . log ( "Type constructed using reflection: " , service ) ; if ( service ) { service . doJob ( Math . E ) ; }