Add .toDynamicValueWithDeps into BindingToSyntax #1506
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
toDynamicValueWithDeps
method binds an abstraction to a dynamic value with required dependencies from the container in a declarative way.Description
I've addded
toDynamicValueWithDeps
method into BindingToSyntax class which basically usestoDynamicValue
method and context it provides under the hood of the new method.Related Issue
None.
Motivation and Context
Let's say we have the following classes:
I would like to create a binding for
Ninja
class which depends on abstract shuriken and katana. Without the new method we would do something like this:The code might be even longer, especially when it's required to inject more dependencies. To make binding notation shorter we could introduce a method which accepts a list of dependencies and a factory which
toDynamicValueWithDeps
method actually does:Looking forward, it should be possible to remove
as const
for dependencies using const type parameters when the library will use TypeScript 5.How Has This Been Tested?
I've added
should be able to resolve all dependencies using toDynamicValueWithDeps
test case intocontainer.test.ts
.Types of changes
Checklist: