Inversify Tagged vs Named bindings with autoBindInjectable

1.3k views Asked by At

I've been trying to understand the difference between Inversify @tagged and @named bindings. I cannot seem to find any documentation which defines the difference between the two. They seem rather synonymous.

Additionally, when using the Container's autoBindInjectable setting, I am even more confused how/where to define an object's tag or name. There does not seem to be a way with the @injectable() annotation. What does the object get bound using as an identifier? Does it use the Class as the identifier?

I did see that the inversify-binding-decorators lib adds the @provide() and @fluentProvide().whenTargetTagged() decorators, but does that then eliminate the need for the @injectable() decorator altogether?

The docs indicate:

let container = new Container({ autoBindInjectable: true });
container.isBound(Ninja);          // returns false
container.get(Ninja);              // returns a Ninja
container.isBound(Ninja);          // returns true

However, it does not show/indicate how to use the @injectable() annotation to allow for the autobind, other than just the generic docs:

@injectable()
class Ninja implements Warrior {}

But then how do you define @tagged or @named bindings? And is there a reason why to choose @tagged over @named? Or is the only way to use the inversify-binding-decorators lib?

0

There are 0 answers