How to use the typedi.Container function in typedi

To help you get started, we’ve selected a few typedi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rockstat / front / dist / Dispatcher.js View on Github external
// Real destination
                const [service, method] = this.rpcHandlers[key];
                return await this.rpc.request(service, method, msg);
            }
            return this.defaultHandler(key, msg);
        };
        this.defaultHandler = async (key, msg) => {
            return {
                key: key,
                id: msg.id
            };
        };
        this.log = typedi_1.Container.get(rock_me_ts_1.Logger).for(this);
        this.status = new rock_me_ts_1.AppStatus();
        this.log.info('Starting');
        this.appConfig = typedi_1.Container.get(rock_me_ts_1.AppConfig);
        this.idGen = typedi_1.Container.get(rock_me_ts_1.TheIds);
    }
    /**
github rockstat / front / dist / BrowserLib.js View on Github external
constructor() {
        this.loaded = false;
        this.log = typedi_1.Container.get(rock_me_ts_1.Logger).for(this);
        const appConfig = typedi_1.Container.get(rock_me_ts_1.AppConfig);
        this.dev = appConfig.env === constants_1.ENV_DEV;
        this.options = appConfig.static;
        // warmup lib
        this.lib();
        this.log.info({
            fn: this.options.file,
            size: `${Math.round(this.content.length / 1024)}kb`,
            dev: this.dev
        }, 'loaded browser lib');
    }
    lib() {
github rockstat / front / dist / http / http_router.js View on Github external
constructor(options) {
        this.router = new FindMyWay();
        this.serviceMap = options.channels;
        this.customRoutes = options.routes;
        this.log = typedi_1.Container.get(rock_me_ts_1.Logger).for(this);
        this.metrics = typedi_1.Container.get(rock_me_ts_1.Meter);
        this.setupRoutes();
        // Default route (404)
        this.defaultRoute = {
            params: {},
            handler: (payload) => {
                return Object.assign(payload, {
                    params: payload.params,
                    key: constants_1.PATH_HTTP_404,
                    channel: constants_1.CHANNEL_HTTP,
                });
            }
        };
    }
    /**
github axetroy / kost / build / src / app.js View on Github external
async start(startOptions = {}) {
        const controllerFiles = (await fs.readdir(path_1.paths.controller)).filter(file => /\.controller\.t|js$/.test(file));
        const serviceFiles = (await fs.readdir(path_1.paths.service)).filter(file => /\.service.t|js$/.test(file));
        const app = this.app;
        const context = typedi_1.Container.get(context_1.default);
        const config = await config_1.loadConfig();
        context.config = config;
        context.params = startOptions;
        if (startOptions.enabled) {
            const { bodyParser, proxy, view, cors } = startOptions.enabled;
            const staticServer = startOptions.enabled.static;
            if (bodyParser) {
                let bodyParserConfig = {};
                if (bodyParser !== true) {
                    bodyParserConfig = bodyParser;
                }
                app.use(require("koa-bodyparser")(bodyParserConfig));
            }
            if (staticServer) {
                const FileServer = require("koa-static");
                let StaticFileServerConfig = {
github jmaicaaan / express-starter-ts / dist / app.js View on Github external
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var routing_controllers_1 = require("routing-controllers");
var typedi_1 = require("typedi");
var index_1 = require("./controllers/index");
require("reflect-metadata");
routing_controllers_1.useContainer(typedi_1.Container);
var app = routing_controllers_1.createExpressServer({
    controllers: [
        index_1.IntroController,
        index_1.UserController,
        index_1.TestController
    ]
});
var port = process.env.PORT || 1111;
app.listen(port, function () {
    console.log("The server is starting at http://localhost:" + port);
});
//# sourceMappingURL=app.js.map
github rockstat / front / dist / http / ws_server.js View on Github external
constructor() {
        this.socksState = new WeakMap();
        this.options = typedi_1.Container.get(rock_me_ts_1.AppConfig).ws;
        this.dispatcher = typedi_1.Container.get(Dispatcher_1.Dispatcher);
        this.log = typedi_1.Container.get(rock_me_ts_1.Logger).for(this);
    }
    get httpOptions() {
github rockstat / front / dist / http / http_server.js View on Github external
constructor() {
        const config = typedi_1.Container.get(rock_me_ts_1.AppConfig);
        const logger = typedi_1.Container.get(rock_me_ts_1.Logger);
        this.metrics = typedi_1.Container.get(rock_me_ts_1.Meter);
        this.idGen = typedi_1.Container.get(rock_me_ts_1.TheIds);
        this.dispatcher = typedi_1.Container.get(Dispatcher_1.Dispatcher);
        this.browserLib = typedi_1.Container.get(BrowserLib_1.BrowserLib);
        this.options = config.http;
        this.title = config.get('name');
        this.identopts = config.identify;
        this.uidkey = this.identopts.param;
        this.clientopts = config.client.common;
        this.log = logger.for(this);
        this.router = new http_router_1.Router(this.options);
        this.cookieExpires = new Date(new Date().getTime() + this.identopts.cookieMaxAge * 1000);
        this.cookieDomain = this.identopts.cookieDomain === 'auto' && this.identopts.domain
            ? '.' + helpers_1.autoDomain(this.identopts.domain)
            : undefined;
    }
    /**
github rockstat / front / dist / http / http_server.js View on Github external
constructor() {
        const config = typedi_1.Container.get(rock_me_ts_1.AppConfig);
        const logger = typedi_1.Container.get(rock_me_ts_1.Logger);
        this.metrics = typedi_1.Container.get(rock_me_ts_1.Meter);
        this.idGen = typedi_1.Container.get(rock_me_ts_1.TheIds);
        this.dispatcher = typedi_1.Container.get(Dispatcher_1.Dispatcher);
        this.browserLib = typedi_1.Container.get(BrowserLib_1.BrowserLib);
        this.options = config.http;
        this.title = config.get('name');
        this.identopts = config.identify;
        this.uidkey = this.identopts.param;
        this.clientopts = config.client.common;
        this.log = logger.for(this);
        this.router = new http_router_1.Router(this.options);
        this.cookieExpires = new Date(new Date().getTime() + this.identopts.cookieMaxAge * 1000);
        this.cookieDomain = this.identopts.cookieDomain === 'auto' && this.identopts.domain
            ? '.' + helpers_1.autoDomain(this.identopts.domain)
            : undefined;
    }
github rockstat / front / dist / AppServer.js View on Github external
setup() {
        this.appConfig = new rock_me_ts_1.AppConfig();
        typedi_1.Container.set(rock_me_ts_1.AppConfig, this.appConfig);
        const log = new rock_me_ts_1.Logger(this.appConfig.log);
        typedi_1.Container.set(rock_me_ts_1.Logger, log);
        this.log = log.for(this);
        this.log.info('Starting service');
        typedi_1.Container.set(rock_me_ts_1.Meter, new rock_me_ts_1.Meter(this.appConfig.meter));
        typedi_1.Container.set(rock_me_ts_1.TheIds, new rock_me_ts_1.TheIds());
        const meter = this.meter = typedi_1.Container.get(rock_me_ts_1.Meter);
        typedi_1.Container.set(rock_me_ts_1.RedisFactory, new rock_me_ts_1.RedisFactory({ log, meter, ...this.appConfig.redis }));
        typedi_1.Container.set(Dispatcher_1.Dispatcher, new Dispatcher_1.Dispatcher());
        typedi_1.Container.set(http_1.HttpServer, new http_1.HttpServer());
        typedi_1.Container.set(http_1.WebSocketServer, new http_1.WebSocketServer());
        this.httpServer = typedi_1.Container.get(http_1.HttpServer);
        this.wsServer = typedi_1.Container.get(http_1.WebSocketServer);
        const dispatcher = this.dispatcher = typedi_1.Container.get(Dispatcher_1.Dispatcher);
        dispatcher.setup();
    }
    start() {
github axetroy / kost / build / src / app.js View on Github external
.map(serviceFile => {
            const filePath = path.join(path_1.paths.service, serviceFile);
            let ServiceFactory = require(filePath);
            ServiceFactory = ServiceFactory.default
                ? ServiceFactory.default
                : service_1.default;
            const service = typedi_1.Container.get(ServiceFactory);
            if (service instanceof service_1.default === false) {
                throw new Error(`The file ${filePath} is not a service file.`);
            }
            return service;
        })
            .sort((a) => -a.level);