You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am aware of #500, #505 and inversify-binding-decorators. Nonetheless, I would love to have a container option fallbackToSelf at hand.
Motivation:
not having to type implicit bindings
same convenience as in angular: only @Injectable() and @Inject() are necessary (bindings are not mandatory)
What it does / How it behaves:
Whenever the container would otherwise throw "No matching bindings found..." for an @Injectable() class, it will use itself as the binding and therefore not throw at that point
This "fallback" behavior runs in the "planning" phase, meaning after any manual binding definitions
@Injectable() and container.bind will not be affected at all by this container option
container.get method will need changes (specifically the planning logic)
@provide decorator of inversify-binding-decorators does not do the job, because the container must be known at "decorating" phase (which I consider an antipattern btw)
If possible, fallbackToSelf will not add a binding at any point, but rather fall back to the "toSelf()" binding if no binding is defined for an @Injectable() class
Some examples:
@injectable()classA{}
@injectable()classB{constructor(a: A){}}
@injectable()classAFake{}classC{}constcontainer1=newContainer({fallbackToSelf: true});container1.get(A);// does not throw, returns transient Acontainer1.get(B);// does not throw, returns transient Bconstcontainer2=newContainer({defaultScope: 'Singleton',fallbackToSelf: true});container2.get(A);// does not throw, returns singleton Acontainer2.get(B);// does not throw, returns singleton Bconstcontainer3=newContainer({fallbackToSelf: true});container3.bind(A).toSelf().inSingletonScope();container3.get(A);// returns singleton A because of explicit bindingcontainer3.get(B);// does not throw, returns transient B with singleton Aconstcontainer4=newContainer({fallbackToSelf: true});container4.bind(A).to(AFake);container4.get(A);// returns transient AFake because of explicit bindingcontainer4.get(B);// does not throw, returns transient B with transient AFakeconstcontainer5=newContainer({fallbackToSelf: true});container5.get(C): // still throws -> No matching bindings found
I tried to do this somehow with a middleware, but I think it is not possible.
The text was updated successfully, but these errors were encountered:
I am aware of #500, #505 and inversify-binding-decorators. Nonetheless, I would love to have a container option fallbackToSelf at hand.
Motivation:
What it does / How it behaves:
Some examples:
I tried to do this somehow with a middleware, but I think it is not possible.
The text was updated successfully, but these errors were encountered: