Skip to content

Commit

Permalink
fix: child container inherits autoRegister
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Oct 24, 2024
1 parent f11f4c7 commit 0037bf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/__tests__/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ describe("Container", () => {
});

it("should handle hierarchical injection", () => {
const container = new Container({
defaultScope: Scope.Container,
autoRegister: true,
});

const Env = Type<string>("Env");
container.register(Env, {useValue: "production"});

const child = container.createChild();
expect(child.autoRegister).toBeTruthy();
expect(child.defaultScope).toBe(Scope.Container);

expect(child.isRegistered(Env)).toBe(true);
expect(child.resolve(Env)).toBe("production");
expect(child.resolveAll(Env)).toEqual(["production"]);
Expand Down
1 change: 1 addition & 0 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Container {
return new Container({
parent: this,
defaultScope: this.defaultScope,
autoRegister: this.autoRegister,
});
}

Expand Down

0 comments on commit 0037bf6

Please sign in to comment.