container-ioc
container-ioc copied to clipboard
Simplify dependency injection syntax in constructor with Reflect API
Implementing this feature is a great way to learn Reflect API and Typescript decorators. I've provided link to a great article on this topic.
Typescript Decorators and Reflect API
- Use Reflect API to simplify injection syntax.
- That can only be possible with Typescript, don't try to apply this feature to es5+.
- Update docs according to this feature.
@Injectable()
class AppService {
constructor(private http: HttpService) {} // instead of @Inject(HttpService) private http: HttpService
}
@Injectable()
class HttpService {
}
container.register([HttpService, AppService])
Thanks for suggestion @thohoh I'll take a look at this one. Looks like an interesting topic to learn. I'll reach out if I have any questions.
@Tolowe Please let me know if you're currently working on it or not. If not, I'll implement that on this weekend.
@thohoh I didnt make it very far on this one - go for it. Sorry about that.
@Tolowe That's okay, we all have things to do apart from open source :D. I'm gonna roll it out soon.
@thohoh I'd suggestion you re-consider the use reflect-metadata due to a known limitation (further on this below).
Currently we're using inversify in one of our projects and have stumbled across a serious issue that has lead us to re-evaluate the use of inversify and look for other IOC frameworks in Typescript (which has lead us to container-ioc).
Here's a link to the original issue: https://github.com/inversify/InversifyJS/issues/737
Or you could possibly implement this feature, as a feature that would work if reflect-metadata is available (but not something that I'd add as a dependency into the container-ioc). I.e. if users want the proposed capabilities suggested by this issue, then they'd need to manually import reflect-metadata.
@DonJayamanne Hello Don. Yes I totally agree with your suggestion. I had this in my mind at the beginning. It's really easy to implement.