feat(di): added resolveAndInstantiate and instantiateResolved to Injector

These two methods can be used to create objects in the context of the injector without storing them in the injector.
This commit is contained in:
vsavkin
2015-08-06 10:33:46 -07:00
parent ff1b110ae1
commit 06da60f4b7
3 changed files with 46 additions and 2 deletions

View File

@ -395,6 +395,29 @@ export function main() {
});
});
describe('resolveAndInstantiate', () => {
it('should instantiate an object in the context of the injector', () => {
var inj = Injector.resolveAndCreate([Engine]);
var car = inj.resolveAndInstantiate(Car);
expect(car).toBeAnInstanceOf(Car);
expect(car.engine).toBe(inj.get(Engine));
});
it('should not store the instantiated object in the injector', () => {
var inj = Injector.resolveAndCreate([Engine]);
inj.resolveAndInstantiate(Car);
expect(() => inj.get(Car)).toThrowError();
});
});
describe('instantiate', () => {
it('should instantiate an object in the context of the injector', () => {
var inj = Injector.resolveAndCreate([Engine]);
var car = inj.instantiateResolved(Injector.resolve([Car])[0]);
expect(car).toBeAnInstanceOf(Car);
expect(car.engine).toBe(inj.get(Engine));
});
});
describe("depedency resolution", () => {
describe("@Self()", () => {