inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.17k stars 713 forks source link

inversify-binding-decorators provide should use reflect-metadata instead of decorator factories #836

Open kbirger opened 6 years ago

kbirger commented 6 years ago

I noticed that the inversify-express-utils package allows the use of decorators that automatically get picked up by the container during the server initialization via the use of the reflect-metadata package. This is very convenient because you don't need to pass on your container to different classes.

The inversify-binding-decorators package follows a pattern of importing a factory, passing it your container, and generating a decorator. This seems clunky and adds a smell to the code.

Would it not be possible to update the package to work similar to inversify-express-utils? To keep the packages decoupled, there could be a function on the binding-decorators package like bindProviders(container), which you call from your resolution root, which then traverses all the registered @provide decorators and binds them.

Context

As of right now, this package doesn't add much value to me, since I don't want to pass my container around to each class which uses a provider.

dcavanagh commented 6 years ago

@kbirger I don't see why this can't be done. Would you like to make a PR?

dcavanagh commented 6 years ago

@kbirger Awesome PR !!! Thanks a lot! Looks like it was a lot of work! #124

@remojansen will probably release it sometime today

kbirger commented 6 years ago

Thanks @AltekkeE, it's no trouble.

remojansen commented 6 years ago

@kbirger very good PR thanks a lot :100: