本文整理汇总了TypeScript中inversify.Container.unbind方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Container.unbind方法的具体用法?TypeScript Container.unbind怎么用?TypeScript Container.unbind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inversify.Container
的用法示例。
在下文中一共展示了Container.unbind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("Should resolve from container directly", () => {
const container = new Container();
const {
lazyInject,
lazyInjectNamed,
lazyInjectTagged,
lazyMultiInject
} = getDecorators(container, false);
const FOO = "FOO";
const BAR = "BAR";
@injectable()
class Foo {
}
@injectable()
class NamedFoo {
}
@injectable()
class TaggedFoo {
}
container.bind<Foo>(FOO).to(Foo);
container.bind<NamedFoo>(BAR).to(NamedFoo).whenTargetNamed("bar");
container.bind<TaggedFoo>(BAR).to(TaggedFoo).whenTargetTagged("bar", true);
@injectable()
class Test {
@lazyInject(FOO) public foo: Foo;
@lazyMultiInject(FOO) public foos: Foo[];
@lazyInjectNamed(BAR, "bar") @named("bar") public namedFoo: Foo;
@lazyInjectTagged(BAR, "bar", true) @tagged("bar", true) public taggedFoo: Foo;
}
const sut: any = new Test();
function actual(key: string): any {
return sut[key];
}
expect(actual("foo")).to.be.instanceof(Foo);
expect(actual("foos")[0]).to.be.instanceof(Foo);
expect(actual("namedFoo")).to.be.instanceof(NamedFoo);
expect(actual("taggedFoo")).to.be.instanceof(TaggedFoo);
function throws(key: string): () => any {
return () => {
return sut[key];
};
}
container.unbind(FOO);
container.unbind(BAR);
expect(throws("foo")).to.throw(
"No matching bindings found for serviceIdentifier: FOO"
);
expect(throws("foos")).to.throw(
"No matching bindings found for serviceIdentifier: FOO"
);
expect(throws("namedFoo")).to.throw(
"No matching bindings found for serviceIdentifier: BAR"
);
expect(throws("taggedFoo")).to.throw(
"No matching bindings found for serviceIdentifier: BAR"
);
});
示例2: afterEach
afterEach(async () => {
await connection.close();
container.unbind(registry.ORMConnectionOptions);
container.unbind(registry.ORMConnection);
});