Skip to content

Commit 4753b85

Browse files
authored
Merge pull request #21 from slavafomin/feat-token-factory
Container.registerService() should support tokenized services from factories
2 parents 4a93dfb + 9c4b121 commit 4753b85

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/Container.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,35 @@ describe("Container", function() {
264264

265265
});
266266

267+
it("should support tokenized services from factories", function() {
268+
269+
interface Vehicle {
270+
getColor(): string;
271+
}
272+
273+
class Bus implements Vehicle {
274+
getColor (): string {
275+
return "yellow";
276+
}
277+
}
278+
279+
class VehicleFactory {
280+
createBus(): Vehicle {
281+
return new Bus();
282+
}
283+
}
284+
285+
const VehicleService = new Token<Vehicle>();
286+
287+
Container.registerService({
288+
id: VehicleService,
289+
factory: [VehicleFactory, "createBus"]
290+
});
291+
292+
Container.get(VehicleService).getColor().should.be.equal("yellow");
293+
294+
});
295+
267296
});
268297

269298
});

0 commit comments

Comments
 (0)