diff --git a/test/bugs/bugs.test.ts b/test/bugs/bugs.test.ts index d2d468332..20cd7c476 100644 --- a/test/bugs/bugs.test.ts +++ b/test/bugs/bugs.test.ts @@ -653,7 +653,7 @@ describe("Bugs", () => { }); - it("Should be able inject into abstract base class without decorators", () => { + it("Should be able to inject into abstract base class without decorators", () => { let TYPES = { Warrior: "Warrior", @@ -736,4 +736,75 @@ describe("Bugs", () => { expect(samurai.primaryWeapon.name).to.eql("Katana"); }); + it("Should be able to combine unmanaged and managed injections ", () => { + + interface Model { + instance: T; + } + + interface RepoBaseInterface { + model: Model; + } + + class Type { + public name: string; + public constructor() { + this.name = "Type"; + } + } + + @injectable() + class RepoBase implements RepoBaseInterface { + + public model: Model; + + constructor( + // using @unmanaged() here is right + // because entityType is NOT Injected by inversify + @unmanaged() entityType: { new (): T; } + ) { + this.model = { instance: new entityType() }; + } + + } + + @injectable() + class TypedRepo extends RepoBase { + constructor() { + super(Type); // unmanaged injection (NOT Injected by inversify) + } + } + + @injectable() + class BLBase { + + public repository: RepoBaseInterface; + + constructor( + // using @unmanaged() here would wrong + // because repository is injected by inversify + repository: RepoBaseInterface + ) { + this.repository = repository; + } + } + + @injectable() + class TypedBL extends BLBase { + constructor( + repository: TypedRepo // Injected by inversify (no @inject required) + ) { + super(repository); // managed injection (Injected by inversify) + } + } + + const container = new Container(); + container.bind(TypedRepo).toSelf(); + container.bind("TypedBL").to(TypedBL); + + const typedBL = container.get("TypedBL"); + expect(typedBL.repository.model.instance.name).to.eq(new Type().name); + + }); + });