本文整理汇总了TypeScript中inversify.Kernel.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Kernel.get方法的具体用法?TypeScript Kernel.get怎么用?TypeScript Kernel.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inversify.Kernel
的用法示例。
在下文中一共展示了Kernel.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
});
示例2: 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);
}
示例3: 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();
}));
示例4: getUserName
@Get('/',
kernel.get<express.RequestHandler>('CustomMiddleware'),
kernel.get<express.RequestHandler>('Morgan'))
getUserName(req: any, res: any) {
res.send(req.user.username);
}
示例5:
export function getInstance<T>(name:string): T {
return kernel.get<T>(name);
}
示例6: getRouter
export function getRouter(): RouteBuilder {
return kernel.get<RouteBuilder>(RouteBuilder);
}
示例7: Kernel
// config inversify (dependency injection)
var kernel = new Kernel();
kernel.bind<Logger>(TYPES.Logger).to(LoggerBasic).inSingletonScope();
kernel.bind<ParkingService>(TYPES.ParkingService).to(ParkingServiceBasic);
kernel.bind<UserService>(TYPES.UserService).to(UserServiceBasic);
kernel.bind<TestDataService>(TYPES.TestDataService).to(TestDataServiceBasic).inSingletonScope();
kernel.bind<DistanceService>(TYPES.DistanceService).to(DistanceServiceBasic);
kernel.bind<TrackingService>(TYPES.TrackingService).to(TrackingServiceBasic);
kernel.bind<ParkingRepository>(TYPES.ParkingRepository).to(ParkingRepositoryBasic).inSingletonScope();
kernel.bind<UserRepository>(TYPES.UserRepository).to(UserRepositoryBasic).inSingletonScope();
kernel.bind<TrackingRepository>(TYPES.TrackingRepository).to(TrackingRepositoryBasic).inSingletonScope();
kernel.bind<GoogleDistanceMatrixKey>(TYPES.GoogleDistanceMatrixKey).to(GoogleDistanceMatrixKeyBasic).inSingletonScope();
// some variables
let version = '0.1.3';
let logger: Logger = kernel.get<Logger>(TYPES.Logger);
let parkingService: ParkingService = kernel.get<ParkingService>(TYPES.ParkingService);
let testDataService: TestDataService = kernel.get<TestDataService>(TYPES.TestDataService);
let userService: UserService = kernel.get<UserService>(TYPES.UserService);
let trackingService: TrackingService = kernel.get<TrackingService>(TYPES.TrackingService);
// mongodb (with mongoose) connection
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test');
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
var serverError = function (response: Response, message: string, user?: User) {
logger.error(message, user);
response.type('application/json; charset=utf-8');
response.writeHead(500);
response.write('{"error": "' + message + '"}');