di.js
di.js copied to clipboard
example how to use it with typescript
any example how to use it in a typescript 1.5 and integrate with its decorators new module system?
Try this, it combines di.js library and new typescript annotations.
https://github.com/VaclavObornik/di-ts
Hello!
Thank you for this great module and your hard work!
However, I'm very interested to use it in my next project with TypeScript 2.2 and Node.js. Is it possible? If so, what are your recommendations, how do I integrate it with TypeScript, is there a typings?
Sadly, @VaclavObornik 's module appears to be severely outdated and broken (and all the other modules I've also found).
@vojtajina could you elaborate on this please? Thank you!
If someone is interested, I've found a way to use DI from Angular 2 directly. Please read this comprehensive material: https://angular.io/docs/ts/latest/guide/dependency-injection.html#!#di-metadata.
Example:
import 'reflect-metadata';
import {ReflectiveInjector, Injectable} from '@angular/core';
@Injectable()
class Engine {
constructor () {
console.log('Engine is created');
}
}
@Injectable()
class Car {
constructor (public engine: Engine) {
console.log('Car is created', engine);
}
}
let injector = ReflectiveInjector.resolveAndCreate([Car, Engine]);
const car = injector.get(Car);
You will also need the following in your tsconfig.json:
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
And don't forget to install rxjs
.