Tag: inversifyjs

InversifyJS:从容器中检索对象时出错

我使用InversifyJS来设置某种dynamic绑定并在NodeJS上运行它。 我遇到的问题是我得到的错误,但没有消息,只有一个堆栈跟踪。 Main类 export class Main { public static getCalculator(config: string): Calculator { try { var container: Container = new KeyFeatureContainer(config).getContainer(); debugger; // error here ! return container.get<Calculator>(TYPES.Calculator); } catch (error) { debugger; return null; } } } 这个类用一个jsonstring调用KeyFeatureContainer ,用来configuration所有的绑定(以一种dynamic的方式),然后检索容器。 KeyFeatureContainer类 export class KeyFeatureContainer { private _container: Container; public constructor(config: string) { var jsonConfig: any[] […]

Inversify:与类名称的上下文注入

我正在尝试使用inversify将注入器注入到不同的类中。 我想将目标类名称传递给logging器对其进行分类。 问题是我无法从创build绑定的位置访问目标名称: container.bind<log4js.Logger>(Types.Logger).toDynamicValue(context => { let className = context….?; // Finds class name return log4js.getLogger(className); }); 除了在接收logging器的对象中创buildlogging器之后设置logging器之外,还有其他方法吗? 谢谢! 安托万

如何注入一个asynchronous依赖inversify?

我有TypeScript应用程序,我正在使用Inversify for IoC。 我有一个连接类: 'use strict'; import { injectable } from 'inversify'; import { createConnection, Connection } from "typeorm"; import { Photo, PhotoMetadata, Author, Album } from '../index'; @injectable() class DBConnectionManager { public createPGConnection(): Promise<Connection> { return createConnection({ driver: { type: "postgres", host: "host", port: 5432, username: "username", password: "password", database: "username" }, entities: [ […]

使用inversify-express-utils,我怎样才能整合websockets?

我们尝试使用websockets来连接基于inversify-express-utils来扩展我们的打字稿应用程序,但到目前为止还没有运气: import 'reflect-metadata'; import {interfaces, InversifyExpressServer, TYPE} from 'inversify-express-utils'; import { Kernel } from 'inversify'; import {UserController} from './controller/UserController'; import TYPES from './constant/types'; import * as socketIo from 'socket.io'; // set up kernel let kernel = new Kernel(); // create server let server = new InversifyExpressServer(kernel); kernel.bind<interfaces.Controller>(TYPE.Controller).to(UserController).whenTargetNamed(TAGS.UserController); server .build() .listen(3000, 'localhost', () => console.log('listening on […]

InversifyJS – 注射不是一个function

我正在尝试使用InversifyJS来build立一个NodeJS / TypeScript项目,但是我有点麻烦。 过去几天我一直在看这个,不知道这个问题。 一切都build立正确,但是当我尝试启动节点服务器时,我得到以下错误: TypeError: inversify_1.injectable is not a function 我正在运行NodeJS v6.2.2(Windows 10 x64),并安装了TypeScript 1.8。 我已经尝试使用VS2015和gulpbuild设。 下面是我尝试过的最小的例子,经历了同样的错误。 我看不出有什么问题,但是我必须明白一些事情。 (懒散的代码,它应该仍然工作。) server.ts: /// <reference path="./node_modules/reflect-metadata/reflect-metadata.d.ts" /> /// <reference path="./node_modules/inversify-dts/inversify/inversify.d.ts" /> /// <reference path="./typings/index.d.ts" /> import "reflect-metadata" import { Application } from "./app/app" import { ITest, TestClass } from "./app/testclass" import { Kernel, injectable, inject } from […]