本文整理汇总了TypeScript中inversify.Container.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Container.get方法的具体用法?TypeScript Container.get怎么用?TypeScript Container.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inversify.Container
的用法示例。
在下文中一共展示了Container.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
container = createContainer();
container.rebind(Symbols.modules.blocksSubModules.verify).to(BlocksModuleVerify);
inst = instReal = container.get(Symbols.modules.blocksSubModules.verify);
});
示例2: beforeEach
beforeEach(() => {
config = container.get(Symbols.generic.appConfig);
});
示例3: beforeEach
beforeEach(() => {
accountsModule = container.get(Symbols.modules.accounts);
appState = container.get(Symbols.logic.appState);
blockLogic = container.get(Symbols.logic.block);
// accountsModule = container.get(Symbols.modules.accounts);
blocksModule = container.get(Symbols.modules.blocks);
blocksUtils = container.get(Symbols.modules.blocksSubModules.utils);
blockVerify = container.get(Symbols.modules.blocksSubModules.verify);
blocksChain = container.get(Symbols.modules.blocksSubModules.chain);
delegates = container.get(Symbols.modules.delegates);
fork = container.get(Symbols.modules.fork);
// roundsModule = container.get(Symbols.modules.rounds);
// txModule = container.get(Symbols.modules.transactions);
// txLogic = container.get(Symbols.logic.transaction);
// blockLogic = container.get(Symbols.logic.block);
roundsStub = container.get(Symbols.logic.rounds);
transportModule = container.get(Symbols.modules.transport);
dbSequence = container.getTagged(
Symbols.helpers.sequence,
Symbols.helpers.sequence,
Symbols.tags.helpers.dbSequence
);
// busStub = container.get(Symbols.helpers.bus);
schemaStub = container.get(Symbols.generic.zschema);
peersLogic = container.get(Symbols.logic.peers);
txModule = container.get(Symbols.modules.transactions);
txLogic = container.get(Symbols.logic.transaction);
loggerStub = container.get(Symbols.helpers.logger);
blocksModel = container.get(Symbols.models.blocks);
blocksModule.lastBlock = createFakeBlock();
});
示例4: it
it('should return true if 0.1.4b', () => {
container.get<IBlocksStub>(Symbols.modules.blocks).lastBlock = {
height: 11,
} as any;
expect(inst.versionCompatible('0.1.4b')).is.true;
});
示例5: beforeEach
beforeEach(() => {
accModule = container.get(Symbols.modules.accounts);
accModule.stubs.resolveAccountsForTransactions.resolves({});
});
示例6: beforeEach
beforeEach(() => {
sandbox = sinon.createSandbox();
container = createContainer();
loggerStub = container.get(Symbols.helpers.logger);
instance = new BlockProgressLogger(10, 2, 'My message', loggerStub);
});
示例7: beforeEach
beforeEach(() => {
blocksModel = container.get(Symbols.models.blocks);
findAllStub = sandbox.stub(blocksModel, 'findAll').resolves([]);
});
示例8: it
it('should return the same connection when one already exists', async () => {
const newConnection = (await container.get<interfaces.Provider<Connection>>(
registry.ORMConnectionProvider
)()) as Connection;
expect(connection).toBe(newConnection);
});
示例9:
container.bind<interfaces.Config>(Bindings.Config).toDynamicValue(() => {
return container.get<interfaces.ConfigManager>(Bindings.ConfigManager).getConfig() as any;
});
示例10: DbConfig
import { DbConfig, repositoryModule, TYPES as RepoTypes, ICounterRepository } from '@sample-stack/store';
import * as Hemera from 'nats-hemera';
import { pubsub, client as natsClient } from './pubsub';
import { TaggedType } from '@sample-stack/core';
import { database as DEFAULT_DB_CONFIG } from '../../../../config/development/settings.json';
import { logger } from '@sample-stack/utils';
const dbConfig = new DbConfig(DEFAULT_DB_CONFIG);
let counterRepo;
try {
let container = new Container();
container.load(repositoryModule(dbConfig));
logger.info('Running in environment : [%s]', process.env.NODE_ENV);
if (process.env.NODE_ENV === 'development') {
// development
counterRepo = container.get<ICounterRepository>(RepoTypes.ICounterRepository);
} else {
// all other environment
const hemera = new Hemera(natsClient, {
logLevel: process.env.HEMERA_LOG_LEVEL as Hemera.LogLevel || 'info',
childLogger: true,
tag: 'hemera-server',
timeout: 10000,
});
container.bind('Hemera').toConstantValue(hemera);
counterRepo = container.getNamed<ICounterRepository>(RepoTypes.ICounterRepository, TaggedType.MICROSERVICE);
}
} catch (err) {
logger.error('Server start failed when building the containers');
logger.error(err);
示例11: beforeEach
beforeEach(() => {
container = createContainer();
const constants2 = container.get<any>(Symbols.helpers.constants);
blocksModel = container.get(Symbols.models.blocks);
transactionLogicStub = container.get(Symbols.logic.transaction);
transactionsModel = container.get(Symbols.models.transactions);
peersModuleStub = container.get(Symbols.modules.peers);
fakePeers = ['a', 'b', 'c'].map((p) => {
return { object: () => p };
});
peersModuleStub.enqueueResponse('list', {
consensus: 123,
peers : fakePeers,
});
peersModuleStub.enqueueResponse('remove', true);
transactionsModuleStub = container.get(Symbols.modules.transactions);
transactionsModuleStub.enqueueResponse('getMultisignatureTransactionList', [
{ id: '100', signatures: ['01', '02', '03'] },
{ id: '101', signatures: [] },
{ id: '102', signatures: ['04', '05', '06'] },
]);
transactionsModuleStub.enqueueResponse('getMergedTransactionList', [
{ id: 10 },
{ id: 11 },
{ id: 12 },
]);
transportModuleStub = container.get(Symbols.modules.transport);
transportModuleStub.enqueueResponse('receiveTransactions', true);
transportModuleStub.enqueueResponse('receiveSignatures', Promise.resolve());
peersLogicStub = container.get(Symbols.logic.peers);
thePeer = { ip: '8.8.8.8', port: 1234 };
peersLogicStub.enqueueResponse('create', thePeer);
container.bind(Symbols.api.transportV2).to(ProxyTransportV2API.TransportV2API);
blockLogicStub = container.get(Symbols.logic.block);
busStub = container.get(Symbols.helpers.bus);
busStub.enqueueResponse('message', true);
blocksSubmoduleUtilsStub = container.get(
Symbols.modules.blocksSubModules.utils
);
sandbox = sinon.createSandbox();
txs = createRandomTransactions({ send: 10 }).map((t) => toBufferedTransaction(t));
fakeBlock = createFakeBlock({
previousBlock: { id: '1', height: 100 } as any,
timestamp : constants2.timestamp,
transactions : txs,
});
blocksModule = container.get(Symbols.modules.blocks);
blocksModule.lastBlock = fakeBlock;
instance = container.get(Symbols.api.transportV2);
res = {};
req = { headers: {port: 5555}, ip: '80.3.10.20', method: 'aaa', protoBuf: Buffer.from('aabbcc', 'hex'),
url: 'bbb', };
validatorStubs.assertValidSchema = sandbox.stub().returns(true);
validatorStubs.SchemaValid = sandbox.stub().returns(true);
validatorStubs.ValidateSchema = sandbox.stub().returns(true);
protoBufStub = container.get(Symbols.helpers.protoBuf);
protoBufStub.stubs.validate.returns(true);
protoBufStub.stubs.encode.callsFake((data) => new Buffer(JSON.stringify(data), 'utf8'));
});
示例12: Container
export const createContainer = (): Container => {
const container = new Container();
// Generics
container.bind(Symbols.generic.appConfig)
.toConstantValue(JSON.parse(JSON.stringify(require(`${__dirname}/../integration/config.json`))));
container.bind(Symbols.generic.genesisBlock)
.toConstantValue(JSON.parse(JSON.stringify(require(`${__dirname}/../integration/genesisBlock.json`))));
const genesis = container.get<any>(Symbols.generic.genesisBlock)
genesis.generatorPublicKey = Buffer.from(genesis.generatorPublicKey, 'hex');
genesis.blockSignature = Buffer.from(genesis.blockSignature, 'hex');
container.bind(Symbols.generic.socketIO).to(SocketIOStub).inSingletonScope();
container.bind(Symbols.generic.zschema).to(ZSchemaStub).inSingletonScope();
container.bind(Symbols.generic.sequelize).toConstantValue(new Sequelize({
database: 'test',
//dialect: 'sqlite',
dialect: 'postgres',
username: 'root',
password: 'test',
//storage: ':memory',
logging: !('SEQ_SILENT' in process.env),
}));
container.bind(Symbols.helpers.constants).toConstantValue({ ...{}, ...constants });
container.bind(Symbols.helpers.bus).to(BusStub).inSingletonScope();
container.bind(Symbols.helpers.ed).to(EdStub).inSingletonScope();
container.bind(Symbols.helpers.db).to(DbStub).inSingletonScope();
container.bind(Symbols.helpers.migrator).to(MigratorStub).inSingletonScope();
container.bind(Symbols.helpers.exceptionsManager).to(ExceptionsManagerStub).inSingletonScope();
container.bind(Symbols.helpers.jobsQueue).to(JobsQueueStub).inSingletonScope();
container.bind(Symbols.helpers.logger).to(LoggerStub).inSingletonScope();
container.bind(Symbols.helpers.protoBuf).to(ProtoBufHelperStub).inSingletonScope();
// BaseRequest.protoBufHelper = container.get(Symbols.helpers.protoBuf);
container.bind(Symbols.helpers.sequence).to(SequenceStub).inSingletonScope().whenTargetTagged(
Symbols.helpers.sequence,
Symbols.tags.helpers.defaultSequence,
);
container.bind(Symbols.helpers.sequence).to(SequenceStub).inSingletonScope().whenTargetTagged(
Symbols.helpers.sequence,
Symbols.tags.helpers.balancesSequence,
);
container.bind(Symbols.helpers.sequence).to(SequenceStub).inSingletonScope().whenTargetTagged(
Symbols.helpers.sequence,
Symbols.tags.helpers.dbSequence,
);
container.bind(Symbols.helpers.slots).to(SlotsStub).inSingletonScope();
// LOGIC
container.bind(Symbols.logic.account).to(AccountLogicStub).inSingletonScope();
container.bind(Symbols.logic.appState).to(AppStateStub).inSingletonScope();
container.bind(Symbols.logic.block).to(BlockLogicStub).inSingletonScope();
container.bind(Symbols.logic.blockReward).to(BlockRewardLogicStub).inSingletonScope();
container.bind(Symbols.logic.peers).to(PeersLogicStub).inSingletonScope();
container.bind(Symbols.logic.transaction).to(TransactionLogicStub).inSingletonScope();
container.bind(Symbols.logic.transactionPool).to(TransactionPoolStub).inSingletonScope();
container.bind(Symbols.logic.rounds).to(RoundsLogicStub).inSingletonScope();
container.bind(Symbols.logic.broadcaster).to(BroadcasterLogicStub).inSingletonScope();
// Modules
container.bind(Symbols.modules.accounts).to(AccountsModuleStub).inSingletonScope();
container.bind(Symbols.modules.blocks).to(BlocksModuleStub).inSingletonScope();
container.bind(Symbols.modules.blocksSubModules.chain).to(BlocksSubmoduleChainStub).inSingletonScope();
container.bind(Symbols.modules.blocksSubModules.process).to(BlocksSubmoduleProcessStub).inSingletonScope();
container.bind(Symbols.modules.blocksSubModules.utils).to(BlocksSubmoduleUtilsStub).inSingletonScope();
container.bind(Symbols.modules.blocksSubModules.verify).to(BlocksSubmoduleVerifyStub).inSingletonScope();
container.bind(Symbols.modules.delegates).to(DelegatesModuleStub).inSingletonScope();
container.bind(Symbols.modules.forge).to(ForgeModuleStub).inSingletonScope();
container.bind(Symbols.modules.fork).to(ForkModuleStub).inSingletonScope();
container.bind(Symbols.modules.loader).to(LoaderModuleStub).inSingletonScope();
container.bind(Symbols.modules.multisignatures).to(MultisignaturesModuleStub).inSingletonScope();
container.bind(Symbols.modules.peers).to(PeersModuleStub).inSingletonScope();
container.bind(Symbols.modules.rounds).to(RoundsModuleStub).inSingletonScope();
container.bind(Symbols.modules.system).to(SystemModuleStub).inSingletonScope();
container.bind(Symbols.modules.transport).to(TransportModuleStub).inSingletonScope();
container.bind(Symbols.modules.transactions).to(TransactionsModuleStub).inSingletonScope();
// Models
container.bind(Symbols.models.accounts).toConstructor(AccountsModel);
container.bind(Symbols.models.blocks).toConstructor(BlocksModel);
container.bind(Symbols.models.exceptions).toConstructor(ExceptionModel);
container.bind(Symbols.models.forkStats).toConstructor(ForksStatsModel);
container.bind(Symbols.models.migrations).toConstructor(MigrationsModel);
container.bind(Symbols.models.info).toConstructor(InfoModel);
container.bind(Symbols.models.transactions).toConstructor(TransactionsModel);
container.bind(Symbols.models.accounts2Delegates).toConstructor(Accounts2DelegatesModel);
container.bind(Symbols.models.accounts2Multisignatures).toConstructor(Accounts2MultisignaturesModel);
container.bind(Symbols.models.accounts2U_Delegates).toConstructor(Accounts2U_DelegatesModel);
container.bind(Symbols.models.accounts2U_Multisignatures).toConstructor(Accounts2U_MultisignaturesModel);
container.bind(Symbols.models.peers).toConstructor(PeersModel);
container.bind(Symbols.models.rounds).toConstructor(RoundsModel);
container.bind(Symbols.models.roundsFees).toConstructor(RoundsFeesModel);
container.bind(Symbols.models.votes).toConstructor(VotesModel);
container.bind(Symbols.models.signatures).toConstructor(SignaturesModel);
container.bind(Symbols.models.delegates).toConstructor(DelegatesModel);
container.bind(Symbols.models.multisignatures).toConstructor(MultiSignaturesModel);
// TRansactions
container.bind(Symbols.logic.transactions.createmultisig).to(MultiSignatureTransaction).inSingletonScope();
container.bind(Symbols.logic.transactions.delegate).to(RegisterDelegateTransaction).inSingletonScope();
//.........这里部分代码省略.........
示例13: init
/** ORM DB Connection */
const connectionOptions: ConnectionOptions = container.getTagged<
interfaces.Factory<ConnectionOptions>
>(
registry.ORMConnectionOptionsFactory,
'type',
registry.ORMSQLiteConnectionOptionsFactory
)({
autoSchemaSync: true
}) as ConnectionOptions;
container
.bind<ConnectionOptions>(registry.ORMConnectionOptions)
.toConstantValue(connectionOptions);
const connectionProvider: interfaces.Provider<Connection> = container.get<
interfaces.Provider<Connection>
>(registry.ORMConnectionProvider);
/** Express Web App */
container
.bind<interfaces.Factory<express.Application>>(registry.ExpressApp)
.toFactory(expressWebAppDevFactory);
export async function init(): Promise<express.Application> {
await connectionProvider();
const settings = container.get<SettingsServiceAttributes>(
registry.SettingsService
);
const logger = container.get<interfaces.Factory<winston.LoggerInstance>>(
registry.LoggerFactory
示例14: beforeEach
beforeEach(() => {
sandbox = sinon.createSandbox();
container = createContainer();
instance = new TransactionPool();
fakeBus = {message: sandbox.stub().resolves()};
fakeAppState = {get: sandbox.stub()};
jqStub = container.get(Symbols.helpers.jobsQueue);
loggerStub = container.get(Symbols.helpers.logger);
transactionLogicStub = container.get(Symbols.logic.transaction);
accountsModuleStub = container.get(Symbols.modules.accounts);
balanceSequenceStub = container.getTagged(Symbols.helpers.sequence,
Symbols.helpers.sequence, Symbols.tags.helpers.balancesSequence);
// dependencies
(instance as any).bus = fakeBus;
(instance as any).jobsQueue = jqStub;
(instance as any).logger = loggerStub;
(instance as any).appState = fakeAppState;
(instance as any).balancesSequence = balanceSequenceStub;
(instance as any).transactionLogic = transactionLogicStub;
(instance as any).accountsModule = accountsModuleStub;
(instance as any).config = {
broadcasts: {
broadcastInterval: 1500,
releaseLimit: 100,
},
transactions: {
maxTxsPerQueue: 50,
},
};
instance.afterConstruction();
spiedQueues = {
bundled: {},
multisignature: {},
queued: {},
unconfirmed: {},
};
// we preserve behavior of the inner queues but we spy on all methods.
['unconfirmed', 'bundled', 'queued', 'multisignature'].forEach((queueName) => {
if (typeof spiedQueues[queueName] === 'undefined') {
spiedQueues[queueName] = {};
}
['has', 'remove', 'add', 'get', 'reindex', 'list', 'listWithPayload'].forEach((method: string) => {
spiedQueues[queueName][method] = sandbox.spy(instance[queueName], method);
});
});
tx = {
amount : 108910891000000,
asset : {},
fee : 10,
id : '8139741256612355994',
recipientId : '15256762582730568272R',
senderId : '1233456789012345R',
senderPublicKey: Buffer.from('6588716f9c941530c74eabdf0b27b1a2bac0a1525e9605a37e6c0b3817e58fe3', 'hex'),
signature : Buffer.from('f8fbf9b8433bf1bbea971dc8b14c6772d33c7dd285d84c5e6c984b10c4141e9f' +
'a56ace902b910e05e98b55898d982b3d5b9bf8bd897083a7d1ca1d5028703e03', 'hex'),
timestamp : 0,
type : TransactionType.SEND,
};
// Clone the tx to separate objects with different IDs
tx2 = Object.assign({}, tx);
tx2.id = 'tx2';
tx3 = Object.assign({}, tx);
tx3.id = 'tx3';
sandbox.resetHistory();
});
示例15: beforeEach
beforeEach(() => {
sandbox = sinon.createSandbox();
container = createContainer();
createHashSpy = sandbox.spy(supersha, 'sha256');
dummyTransactions = [
{
amount: 108910891000000,
fee: 5,
id: '8139741256612355994',
recipientId: '15256762582730568272R',
senderId: '14709573872795067383R',
senderPublicKey: Buffer.from('35526f8a1e2f482264e5d4982fc07e73f4ab9f4794b110ceefecd8f880d51892', 'hex'),
signature: Buffer.from('f8fbf9b8433bf1bbea971dc8b14c6772d33c7dd285d84c5e6c984b10c4141e9fa56ace' +
'902b910e05e98b55898d982b3d5b9bf8bd897083a7d1ca1d5028703e03', 'hex'),
timestamp: 0,
type: 1,
},
{
amount: 108910891000000,
fee: 3,
id: '16622990339377112127',
recipientId: '6781920633453960895R',
senderId: '14709573872795067383R',
senderPublicKey: Buffer.from('35526f8a1e2f482264e5d4982fc07e73f4ab9f4794b110ceefecd8f880d51892', 'hex'),
signature: Buffer.from('e26edb739d93bb415af72f1c288b06560c0111c4505f11076ca20e2f6e8903d3b00730' +
'9c0e04362bfeb8bf2021d0e67ce3c943bfe0c0193f6c9503eb6dfe750c', 'hex'),
timestamp: 0,
type: 3,
},
{
amount: 108910891000000,
fee: 3,
id: '16622990339377114578',
recipientId: '6781920633453960895R',
senderId: '14709573872795067383R',
senderPublicKey: Buffer.from('35526f8a1e2f482264e5d4982fc07e73f4ab9f4794b110ceefecd8f880d51892', 'hex'),
signature: Buffer.from('e26edb739d93bb415af72f1c288b06560c0111c4505f11076ca20e2f6e8903d3b00730' +
'9c0e04362bfeb8bf2021d0e67ce3c943bfe0c0193f6c9503eb6dfe750c', 'hex'),
timestamp: 0,
type: 2,
},
];
dummyBlock = {
blockSignature: Buffer.from('8c5f2b088eaf0634e1f6e12f94a1f3e871f21194489c76ad2aae5c1b71acd848bc7b' +
'158fa3b827e97f3f685c772bfe1a72d59975cbd2ccaa0467026d13bae50a', 'hex'),
generatorPublicKey: Buffer.from('c950f1e6c91485d2e6932fbd689bba636f73970557fe644cd901a438f74883c5', 'hex'),
numberOfTransactions: 2,
payloadHash: Buffer.from('b3cf5bb113442c9ba61ed0a485159b767ca181dd447f5a3d93e9dd73564ae762', 'hex'),
payloadLength: 8,
previousBlock: '1',
reward: 30000000,
timestamp: 1506889306558,
totalAmount: 217821782000000,
totalFee: 8,
transactions: dummyTransactions,
version: 0,
};
callback = sandbox.spy();
zschemastub = container.get(Symbols.generic.zschema);
blockRewardLogicStub = container.get(Symbols.logic.blockReward);
container.rebind(Symbols.helpers.ed).toConstantValue(ed);
container.rebind(Symbols.logic.block).to(BlockLogic).inSingletonScope();
instance = container.get(Symbols.logic.block);
accLogic = container.get(Symbols.logic.account);
transactionLogicStub = container.get(Symbols.logic.transaction);
// Default stub configuration
blockRewardLogicStub.stubConfig.calcReward.return = 100000;
transactionLogicStub.stubs.getBytes.returns(buffer);
transactionLogicStub.stubs.objectNormalize.returns(null);
data = {
keypair: dummyKeypair,
previousBlock: getFakePrevBlock(),
timestamp: Date.now(),
transactions: dummyTransactions,
};
blocksModel = container.get(Symbols.models.blocks);
});