File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11import "reflect-metadata" ;
22import { Container } from "../../src/Container" ;
33import { Service } from "../../src/decorators/Service" ;
4+ import { AsyncInitializedService } from "../../src/types/AsyncInitializedService" ;
45
56describe ( "Service Decorator" , function ( ) {
67
@@ -99,7 +100,7 @@ describe("Service Decorator", function() {
99100
100101 } ) ;
101102
102- it ( "should support factory function with arguments" , function ( ) {
103+ it ( "should support factory class with arguments on create method " , function ( ) {
103104
104105 @Service ( )
105106 class Engine {
@@ -183,4 +184,28 @@ describe("Service Decorator", function() {
183184 scopedContainer . get ( Engine ) . name . should . be . equal ( "sporty" ) ;
184185 } ) ;
185186
187+ it ( "should support services with asynchronous initialization" , async function ( ) {
188+
189+ @Service ( { asyncInitialization : true } )
190+ class Engine extends AsyncInitializedService {
191+ ignition : string = "off" ;
192+
193+ protected initialize ( ) {
194+ return new Promise ( ( resolve ) => {
195+ setTimeout ( ( ) => {
196+ this . ignition = "running" ;
197+ resolve ( ) ;
198+ } , 0 ) ;
199+ } ) ;
200+ }
201+ }
202+
203+ @Service ( )
204+ class Car {
205+ constructor ( public engine : Engine ) {
206+ }
207+ }
208+
209+ ( await Container . getAsync ( Car ) ) . engine . ignition . should . be . equal ( "running" ) ;
210+ } ) ;
186211} ) ;
You can’t perform that action at this time.
0 commit comments