當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript inversify.Kernel類代碼示例

本文整理匯總了TypeScript中inversify.Kernel的典型用法代碼示例。如果您正苦於以下問題:TypeScript Kernel類的具體用法?TypeScript Kernel怎麽用?TypeScript Kernel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Kernel類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

    it("should call the configFn before the errorConfigFn", (done) => {
        let middleware = function(req: restify.Request, res: restify.Response, next: restify.Next) { return; };
        let configFn = sinon.spy((app: restify.Server) => { app.use(middleware); });
        let errorConfigFn = sinon.spy((app: restify.Server) => { app.use(middleware); });
        let kernel = new Kernel();

        @injectable()
        class TestController {}

        kernel.bind(TYPE.Controller).to(TestController);
        let server = new InversifyRestifyServer(kernel);

        server.setConfig(configFn)
            .setErrorConfig(errorConfigFn);

        expect(configFn.called).to.be.false;
        expect(errorConfigFn.called).to.be.false;

        server.build();

        expect(configFn.calledOnce).to.be.true;
        expect(errorConfigFn.calledOnce).to.be.true;
        expect(configFn.calledBefore(errorConfigFn)).to.be.true;
        done();
    });
開發者ID:hsyngkby,項目名稱:inversify-restify-utils,代碼行數:25,代碼來源:server.test.ts

示例2: testZone

        testZone(async () => {
            const kernel = new inversify.Kernel();
            kernel.bind(TestService).to(TestService);
            kernel.applyMiddleware(
                interceptor.methodInterceptorMiddleware(kernel, {
                    targetClass: /TestService/
                }, TestInterceptor)
            );

            const testService = kernel.get(TestService);
            interceptorCall = false;
            await testService.invoke();
            expect(interceptorCall).toBeTruthy();

        }));
開發者ID:takeshi,項目名稱:inversity-async-method-interceptor,代碼行數:15,代碼來源:async-method-interceptor.spec.ts

示例3: Kernel

import {Kernel} from "inversify";

import {INinja, Ninja} from "./Ninja";
import {IKatana, Katana} from "./Katana";
import {IShuriken, Shuriken} from "./Shuriken";

var kernel = new Kernel();
kernel.bind<INinja>("INinja").to(Ninja);
kernel.bind<IKatana>("IKatana").to(Katana);
kernel.bind<IShuriken>("IShuriken").to(Shuriken);

export default kernel;
開發者ID:ducksoupdev,項目名稱:typescript-ioc,代碼行數:12,代碼來源:inversify.config.ts

示例4: Kernel

import { Kernel, makePropertyInjectDecorator, INewable } from 'inversify';
import { makeFluentProvideDecorator } from 'inversify-binding-decorators';
import Dockerode from 'dockerode';

export const kernel = new Kernel();

// bind 3rd party deps
kernel.bind(Dockerode).toConstantValue(Dockerode);

const provide = makeFluentProvideDecorator(kernel);

export function provideInstance (identifier: string|Symbol|INewable<any>) {
  return provide(identifier).done();
}

export function provideSingleton (identifier: string|Symbol|INewable<any>) {
  return provide(identifier).inSingletonScope().done();
}

export const inject = makePropertyInjectDecorator(kernel);
開發者ID:Webysther,項目名稱:dwatch,代碼行數:20,代碼來源:IOC.ts

示例5: Kernel

/// <reference path="../node_modules/inversify-dts/inversify/inversify.d.ts" />
/// <reference path="../node_modules/reflect-metadata/reflect-metadata.d.ts" />

import "reflect-metadata";
import * as express from 'express';
import { Kernel } from 'inversify';
import { Server } from './framework/server';
import { FooController } from './controllers/foo-controller';
import { FooService } from './services/foo-service';

// set up kernel
var kernel = new Kernel();
kernel.bind<FooService>('FooService').to(FooService);
kernel.bind<FooController>('FooController').to(FooController);

// create server
var server = new Server(kernel);

server
    .build()
    .listen(3000, 'localhost', callback);

function callback() {
    console.log('listening on http://localhost:3000');
}
開發者ID:codyjs,項目名稱:express-typescript-ioc,代碼行數:25,代碼來源:app.ts

示例6: registerUIElements

export function registerUIElements() {
    let output = vscode.window.createOutputChannel("Test Kitchen");
    kernel.bind<vscode.OutputChannel>("KitchenOutput").toConstantValue(output);

    let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
    statusBarItem.command = "kitchen.terminateProcess";
    kernel.bind<vscode.StatusBarItem>("KitchenStatusBarItem").toConstantValue(statusBarItem);
}
開發者ID:jirkafajfr,項目名稱:vscode-kitchen,代碼行數:8,代碼來源:inversify.config.ts

示例7: get_i18n

function get_i18n(lang_id: string) {
	const [ lang, region ] = lang_id.split('_')
	let defaults: IIntl[] = []
	if (region)
		defaults = defaults.concat(kernel.getAllTagged<IIntl>('intl', 'lang', lang_id))
	defaults = defaults.concat(kernel.getAllTagged<IIntl>('intl', 'lang', lang))
	return Object.assign.apply(undefined, [ {} ] .concat(defaults))
}
開發者ID:Offirmo,項目名稱:web-tech-experiments,代碼行數:8,代碼來源:index.ts

示例8: callback

server.setConfig((app) => {

    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());
    app.use(morgan('combined'));
    app.use(cors({
        origin: (origin, callback) => {
            try {
                let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
                callback(null, ok);
            } catch (e) {
                callback(e, null);
            }

        }
    }));
    app.use(jwt({ secret: config.appSecret })
        .unless({
            path: ['/api/account/login', '/setup', '/',
                {
                    url: '/api/donors',
                    methods: ['GET', 'POST']
                }]
        }));

   let feed: DonorsFeed = kernel.get<DonorsFeed>(TYPES.DonorsFeed);
   feed.start(httpServer);
});
開發者ID:kibiluzbad,項目名稱:kamrusepa,代碼行數:28,代碼來源:server.ts

示例9: expressMvc

export function expressMvc(...controllers: any[]): ExpressMvc {
    debug("Starting ExpressMVC");
    // Handle registering Controllers
    controllers.forEach(controller => {
        debug(`Binding controller (${controller.name})`);
        kernel.bind<mvcController>(controller).to(controller);
        debug(`Bound controller (${controller.name})`);
    });
    debug('Finished binding controllers...');
    return kernel.get<ExpressMvc>(ExpressMvc);
}
開發者ID:DemgelOpenSource,項目名稱:demgel-mvc,代碼行數:11,代碼來源:setup.ts

示例10: getUserName

 @Get('/', 
     kernel.get<express.RequestHandler>('CustomMiddleware'),
     kernel.get<express.RequestHandler>('Morgan'))
 getUserName(req: any, res: any) {
     res.send(req.user.username);
 }
開發者ID:codyjs,項目名稱:inversify-express-example,代碼行數:6,代碼來源:controller.ts


注:本文中的inversify.Kernel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。