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


TypeScript Container.bind方法代码示例

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


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

示例1: it

    it("Should support tagged constraints", () => {

        let container = new Container();

        let {
            lazyInjectTagged
        } = getDecorators(container);

        class Warrior {

            @lazyInjectTagged(TYPES.Weapon, "throwwable", false)
            @tagged("throwwable", false)
            public primaryWeapon: Weapon;

            @lazyInjectTagged(TYPES.Weapon, "throwwable", true)
            @tagged("throwwable", true)
            public secondaryWeapon: Weapon;

        }

        container.bind<Weapon>(TYPES.Weapon).to(Sword).whenTargetTagged("throwwable", false);
        container.bind<Weapon>(TYPES.Weapon).to(Shuriken).whenTargetTagged("throwwable", true);

        let warrior1 = new Warrior();
        expect(warrior1.primaryWeapon).to.be.instanceof(Sword);
        expect(warrior1.secondaryWeapon).to.be.instanceof(Shuriken);

    });
开发者ID:inversify,项目名称:inversify-inject-decorators,代码行数:28,代码来源:index.test.ts

示例2: before

 before(() => {
   allStubsContainer = createContainer();
   loggerStub = allStubsContainer.get(Symbols.helpers.logger);
   allStubsContainer.bind(Symbols.modules.cache).toConstantValue({});
   allStubsContainer.bind(Symbols.modules.peers).toConstantValue({});
   appConfig    = JSON.parse(fs.readFileSync(path.resolve('etc/mainnet/config.json'), 'utf8'));
   genesisBlock = JSON.parse(fs.readFileSync(path.resolve('etc/mainnet/genesisBlock.json'), 'utf8'));
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:8,代码来源:AppManager.spec.ts

示例3: beforeEach

 beforeEach(() => {
   container = new Container();
   container
     .bind<SettingsServiceAttributes>(registry.SettingsService)
     .to(MockSettingsService)
     .inSingletonScope();
   container
     .bind<interfaces.Factory<winston.LoggerInstance>>(registry.LoggerFactory)
     .toFactory(loggerFactory);
 });
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:10,代码来源:logger.spec.ts

示例4: createBasicContainer

export function createBasicContainer() {
  const container = new Container();
  container.bind<IConfig>(TYPES.Config).to(Config);

  // scoped console log using debug
  container.bind<ILogger>(TYPES.Logger).toDynamicValue(context => {
    const namedMetadata = context.currentRequest.target.getNamedTag();
    const named = namedMetadata ? namedMetadata.value : '';
    // this way we log to the console only when DEBUG var is set to "job,job:*"
    return new Logger('job', named);
  });

  container.bind<IPipeline>(TYPES.Pipeline).to(Pipeline);
  container.bind<IExtractService>(TYPES.ExtractService).to(ExtractService);
  container
    .bind<ISearchEngineParser>(TYPES.SearchEngineParser)
    .to(BingEngineParser);
  container
    .bind<IJmdictEntryProcessor>(TYPES.JmdictEntryProcessor)
    .to(JmdictEntryProcessor);

  container.bind<IJob>(TYPES.ParseDatabaseJob).to(ParseDatabaseJob);
  container.bind<IJob>(TYPES.AddMetadataJob).to(AddMetadataJob);

  container.bind<IDataStorage>(TYPES.DataStroage).to(DataStorage);

  return container;
}
开发者ID:vnenkpet,项目名称:japanese,代码行数:28,代码来源:inversify.config.ts

示例5: beforeEach

  beforeEach(async () => {
    container = new Container();
    container.load(ormModule);

    // Services
    container
      .bind<SettingsServiceAttributes>(registry.SettingsService)
      .to(MockSettingsService)
      .inSingletonScope();
    mockSettingsService = container.get<SettingsServiceAttributes>(
      registry.SettingsService
    );
    mockSettingsService.loggerTransports = [
      new winston.transports.Console({
        silent: true
      })
    ];
    mockLogger = new winston.Logger();
    const loggerFactory: interfaces.FactoryCreator<winston.LoggerInstance> = (
      context: interfaces.Context
    ) => {
      return () => {
        return mockLogger;
      };
    };
    container
      .bind<interfaces.Factory<winston.LoggerInstance>>(registry.LoggerFactory)
      .toFactory(loggerFactory);

    // ORM
    container
      .bind<ConnectionOptions>(registry.ORMConnectionOptions)
      .toConstantValue({
        autoSchemaSync: true,
        type: 'sqlite',
        database: ':memory:'
      });
    connection = (await container.get<interfaces.Provider<Connection>>(
      registry.ORMConnectionProvider
    )()) as Connection;

    // Express configs
    container
      .bind<CardSetControllerAttributes>(CardSetController)
      .toSelf();
    app = express();
    useContainer(container);
    useExpressServer(app, {
      routePrefix: '/api',
      controllers: [CardSetController],
      development: true
    });
  });
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:53,代码来源:CardSet.spec.ts

示例6: beforeAll

  beforeAll(() => {
    const container = new Container();
    const i18n = setupI18n();
    i18n._ = (id: string) => id;
    container.bind(TYPES.I18n).toConstantValue(i18n);
    container.bind(NotificationServiceType).toConstantValue(mockNS);
    loadNotifications(container);

    notifications = container.get<UIUpdateNotifications>(
      UIUpdateNotificationsType
    );
  });
开发者ID:dcos,项目名称:dcos-ui,代码行数:12,代码来源:notifications-test.ts

示例7: beforeAll

    beforeAll(async () => {
        knex = Knex(DEFAULT_DB_CONFIG);
        await knex.migrate.latest();
        await knex.seed.run();

        const dbConfig = new DbConfig(DEFAULT_DB_CONFIG);
        container = new Container();

        container.bind<DbConfig>('DefaultDbConfig').toConstantValue(dbConfig);

        // container...
        container.bind<ICounterRepository>(TYPES.ICounterRepository).to(CounterRepository);

    });
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:14,代码来源:counter-repository.test.ts

示例8: beforeEach

 beforeEach(() => {
   container = createContainer();
   sandbox = sinon.createSandbox();
   container.bind(Symbols.generic.versionBuild).toConstantValue(versionBuild);
   container
     .bind(Symbols.api.peers)
     .to(PeersAPI)
     .inSingletonScope();
   peersModuleStub = container.get(Symbols.modules.peers);
   peersModuleStub.enqueueResponse('getByFilter', [{object: () => ({ hello: 'world' })}]);
   systemModuleStub = container.get(Symbols.modules.system);
   systemModuleStub.enqueueResponse('getMinVersion', '1.0');
   instance = container.get(Symbols.api.peers);
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:14,代码来源:peersAPI.spec.ts

示例9: beforeEach

 beforeEach(() => {
   dbReturn = [{ id: '2', height: 3 }];
   container.bind('bit').to(RoundsLogic).inSingletonScope();
   const realRoundsLogic = container.get('bit');
   inst['rounds']        = realRoundsLogic;
   findAllStub           = sandbox.stub(blocksModel, 'findAll').resolves(dbReturn);
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:7,代码来源:utils.spec.ts

示例10: beforeEach

 beforeEach(() => {
   container = new Container();
   container
     .bind<interfaces.Factory<ConnectionOptions>>(registry.ORMConnectionOptionsFactory)
     .toFactory<ConnectionOptions>(baseConnectionOptionsFactory)
     .whenTargetTagged('type', registry.ORMBaseConnectionOptionsFactory);
 });
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:7,代码来源:base-options.factory.spec.ts


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