File tree Expand file tree Collapse file tree 7 files changed +51
-6
lines changed Expand file tree Collapse file tree 7 files changed +51
-6
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
1
+ import { BeanFactory } from "./BeanFactory" ;
2
+ import { SugarFactory } from "./SugarFactory" ;
3
+ import { WaterFactory } from "./WaterFactory" ;
4
+
5
+ export class CoffeeMaker {
6
+
7
+ constructor ( container ) {
8
+ this . beanFactory = container . get ( BeanFactory ) ;
9
+ this . sugarFactory = container . get ( SugarFactory ) ;
10
+ this . waterFactory = container . get ( WaterFactory ) ;
11
+ this . authorizationToken = container . get ( "authorizationToken" ) ;
12
+ }
13
+
14
+ make ( ) {
15
+ this . beanFactory . create ( ) ;
16
+ this . sugarFactory . create ( ) ;
17
+ this . waterFactory . create ( ) ;
18
+
19
+ console . log ( "coffee is made. Authorization token: " + this . authorizationToken ) ;
20
+ }
21
+
22
+ }
Original file line number Diff line number Diff line change
1
+ export class SugarFactory {
2
+
3
+ create ( ) {
4
+ console . log ( "sugar created" ) ;
5
+ }
6
+
7
+ }
Original file line number Diff line number Diff line change
1
+ export class WaterFactory {
2
+
3
+ create ( ) {
4
+ console . log ( "water created" ) ;
5
+ }
6
+
7
+ }
Original file line number Diff line number Diff line change
1
+ import "reflect-metadata" ;
2
+ import { Container } from "../../src/index" ;
3
+ import { CoffeeMaker } from "./CoffeeMaker" ;
4
+
5
+ Container . of ( "my-container" ) . set ( "authorizationToken" , "!@#$%^&*" ) ;
6
+ let coffeeMaker = Container . of ( "my-container" ) . get ( CoffeeMaker ) ;
7
+ console . log ( coffeeMaker ) ;
8
+ coffeeMaker . make ( ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -292,6 +292,13 @@ export class ContainerInstance {
292
292
throw new MissingProvidedServiceTypeError ( identifier ) ;
293
293
294
294
params . unshift ( null ) ;
295
+
296
+ // if there are no constructor parameters in the class then pass a container instance into it
297
+ // this allows us to support javascript where we don't have decorators and emitted metadata about dependencies
298
+ // need to be injected, and user can use provided container to get instances he needs
299
+ if ( params . length === 1 )
300
+ params . push ( this ) ;
301
+
295
302
service . value = new ( type . bind . apply ( type , params ) ) ( ) ;
296
303
}
297
304
You can’t perform that action at this time.
0 commit comments