本文整理汇总了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);
});
示例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'));
});
示例3: beforeEach
beforeEach(() => {
container = new Container();
container
.bind<SettingsServiceAttributes>(registry.SettingsService)
.to(MockSettingsService)
.inSingletonScope();
container
.bind<interfaces.Factory<winston.LoggerInstance>>(registry.LoggerFactory)
.toFactory(loggerFactory);
});
示例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;
}
示例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
});
});
示例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
);
});
示例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);
});
示例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);
});
示例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);
});
示例10: beforeEach
beforeEach(() => {
container = new Container();
container
.bind<interfaces.Factory<ConnectionOptions>>(registry.ORMConnectionOptionsFactory)
.toFactory<ConnectionOptions>(baseConnectionOptionsFactory)
.whenTargetTagged('type', registry.ORMBaseConnectionOptionsFactory);
});