当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Container.unload方法代码示例

本文整理汇总了TypeScript中inversify.Container.unload方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Container.unload方法的具体用法?TypeScript Container.unload怎么用?TypeScript Container.unload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inversify.Container的用法示例。


在下文中一共展示了Container.unload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it("Should resolve from container directly", () => {

            const container = new Container();
            const {
                lazyInject,
                lazyInjectNamed,
                lazyInjectTagged,
                lazyMultiInject
            } = getDecorators(container, false);

            const SINGLETON_FOO = "SINGLETON_FOO";
            const FOO = "FOO";
            const BAR = "BAR";

            @injectable()
            class FooBarBase {
            }

            @injectable()
            class SingletonFoo extends FooBarBase {
            }

            @injectable()
            class Foo extends FooBarBase {
            }

            @injectable()
            class Bar extends FooBarBase {
            }

            @injectable()
            class NamedBar extends FooBarBase {
            }

            @injectable()
            class TaggedBar extends FooBarBase {
            }

            const mFoo = new ContainerModule((bind: interfaces.Bind) => {
                bind<FooBarBase>(SINGLETON_FOO).to(SingletonFoo);
                bind<FooBarBase>(FOO).to(Foo);
            });
            const mBar = new ContainerModule((bind: interfaces.Bind) => {
                bind<FooBarBase>(FOO).to(Bar);
                bind<FooBarBase>(BAR).to(NamedBar).whenTargetNamed("bar");
                bind<FooBarBase>(BAR).to(TaggedBar).whenTargetTagged("bar", true);
            });

            container.load(mFoo, mBar);

            @injectable()
            class Test {
                @lazyInject(SINGLETON_FOO) public singletonFoo: FooBarBase;
                @lazyMultiInject(FOO) public foos: FooBarBase[];
                @lazyInjectNamed(BAR, "bar") @named("bar") public namedFoo: FooBarBase;
                @lazyInjectTagged(BAR, "bar", true) @tagged("bar", true) public taggedFoo: FooBarBase;
            }

            const sut: any = new Test();

            function actual(key: string): any {
              return sut[key];
            }

            expect(actual("singletonFoo")).to.be.instanceof(SingletonFoo);
            let foos: FooBarBase[] = actual("foos");
            expect(foos.length).to.equal(2);
            expect(foos[0]).to.be.instanceof(Foo);
            expect(foos[1]).to.be.instanceof(Bar);

            container.unload(mBar);

            expect(actual("singletonFoo")).to.be.instanceof(SingletonFoo);
            foos = actual("foos");
            expect(foos.length).to.equal(1);
            expect(foos[0]).to.be.instanceof(Foo);

            function throws(key: string): () => any {
                return () => {
                  return sut[key];
                };
            }

            expect(throws("namedFoo")).to.throw(
                "No matching bindings found for serviceIdentifier: BAR"
            );
            expect(throws("taggedFoo")).to.throw(
                "No matching bindings found for serviceIdentifier: BAR"
            );

            container.unload(mFoo);

            expect(throws("singletonFoo")).to.throw(
                "No matching bindings found for serviceIdentifier: SINGLETON_FOO"
            );
            expect(throws("foos")).to.throw(
                "No matching bindings found for serviceIdentifier: FOO"
            );
        });
开发者ID:inversify,项目名称:inversify-inject-decorators,代码行数:99,代码来源:issue-730.test.ts


注:本文中的inversify.Container.unload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。