inversify / InversifyJS

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

Feature request: named class injectables #1029

Open varogonz95 opened 5 years ago

varogonz95 commented 5 years ago

Expected Behavior

Add the posibility to do something like the following:

@injectable(/* name class */ "Custom Name")
class Example { }

let container = new Container()
container.bind(Example) /* etc... */
// or...
container.bind(Example, /* named */ "Custom Name") /* etc... */
// or...
container.bind(Example).toSelf(/* named */ "Custom Name") /* etc... */

let result = container.get<Example>("Custom Name")
console.log(result)

Current Behavior

Can't get binded classes with injectable name

Possible Solution

Add string parameter to name classes the same way it works for properties

Steps to Reproduce (for bugs)

  1. None

Context

Your Environment

Stack trace

varogonz95 commented 5 years ago

Oh forget it, I just realized you can name classes from binding with:

container.bind<Type>(Type).toSelf().whenTargetNamed("Some name")

:man_facepalming: