Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify dependency injection syntax in constructor with Reflect API #102

Open
basedalexander opened this issue Nov 19, 2017 · 6 comments
Open

Comments

@basedalexander
Copy link
Member

basedalexander commented Nov 19, 2017

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])
@Tolowe
Copy link
Contributor

Tolowe commented Nov 19, 2017

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.

@basedalexander basedalexander changed the title Simplify dependency injection syntax in constructor. Simplify dependency injection syntax in constructor with Reflect API Dec 2, 2017
@basedalexander
Copy link
Member Author

@Tolowe Please let me know if you're currently working on it or not. If not, I'll implement that on this weekend.

@Tolowe
Copy link
Contributor

Tolowe commented Dec 2, 2017

@ThoHoh I didnt make it very far on this one - go for it. Sorry about that.

@basedalexander
Copy link
Member Author

@Tolowe That's okay, we all have things to do apart from open source :D. I'm gonna roll it out soon.

@basedalexander basedalexander self-assigned this Dec 2, 2017
@DonJayamanne
Copy link

DonJayamanne commented Jan 4, 2018

@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: inversify/InversifyJS#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.

@basedalexander
Copy link
Member Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants