Skip to content

Commit

Permalink
Allowed passing options to child containers (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg authored and remojansen committed Apr 13, 2018
1 parent 83eb36b commit 5e0c9f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class Container implements interfaces.Container {
this._middleware = snapshot.middleware;
}

public createChild(): Container {
const child = new Container();
public createChild(containerOptions?: interfaces.ContainerOptions): Container {
const child = new Container(containerOptions);
child.parent = this;
return child;
}
Expand Down
16 changes: 16 additions & 0 deletions test/container/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,22 @@ describe("Container", () => {
expect(child.parent.guid).to.eql(parent.guid);
});

it("Should be able to override options to child containers", () => {
@injectable()
class Warrior { }

const parent = new Container();
parent.bind(Warrior).toSelf();

const child = parent.createChild({
defaultScope: BindingScopeEnum.Singleton,
});

const singletonWarrior1 = child.get(Warrior);
const singletonWarrior2 = child.get(Warrior);
expect(singletonWarrior1).to.eql(singletonWarrior2);
});

it("Should be able check if a named binding is bound", () => {

const zero = "Zero";
Expand Down

0 comments on commit 5e0c9f4

Please sign in to comment.