import 'reflect-metadata' ; import { ReflectiveInjector , Inject , Injectable , OpaqueToken } from '@angular/core' ; const BUFFER_SIZE = new OpaqueToken ( 'buffer-size' ) ; class Buffer { constructor ( @ Inject ( BUFFER_SIZE ) private size ) { } } class Certificate { } class Crypto { } @ Injectable ( ) class Socket { isOpen : boolean ; constructor ( private buffer ) { } open ( ) { this . isOpen = true ; } } class TLSConnection { public socket : Socket ; public crypto : Crypto ; public certificate : Certificate ; } let injector = ReflectiveInjector . resolveAndCreate ( [ { provide : TLSConnection , useFactory : ( socket , certificate , crypto ) => { let connection = new TLSConnection ( ) ; connection . certificate = certificate ; connection . socket = socket ; connection . crypto = crypto ; socket . open ( ) ; return connection ; } , deps : [ Socket , Certificate , Crypto ] } , { provide : BUFFER_SIZE , useValue : 42 } , Buffer , Socket , Certificate , Crypto ] ) ; console . log ( injector . get ( TLSConnection ) ) ;