-
-
Notifications
You must be signed in to change notification settings - Fork 201
Injection by ID #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Injection by ID #764
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@migus88 I encountered a problem, multiple registration for single interface does not work as expected. Inject IEnumerable will always contain zero elements if the method with ID was used. |
@softshadedev thanks, I will take a look at it! I also want to see how I can move the registration with ID to use the |
@softshadedev I've merged the handling of non-id registrations with id registrations and added a unit test to make sure that collections returned as expected no matter how the dependency is registered. Give it a try. |
WORK IN PROGRESS
This PR is work in progress. While the logic is fully complete, existing tests are passing and new tests are in place, before opening it for a full review, I'd like to give it a better test drive in my own project - to see if I missed something.
Before I open this PR for a review, I might fix some bugs, improve the readability of the changes and add more tests coverage, but overall the core logic shouldn't change, so feel free getting familiar with the change and giving me your suggestions.
Description
As a long time fan of this DI framework, I use it constantly, but I was always missing one feature that I got really used to in Zenject - injection by ID.
I know we can use Factories and that's what I did up until recently, but since I had a little spare time, I wanted to implement the feature in VContainer as well.
My aim was to not introduce any regression and to do it as performant as possible.
Usage:
Benchmarks
Implementation Change
In order to support resolution by ID, I had to turn the
FixedTypeKeyHashTable
class intoFixedTypeObjectKeyHashtable
.I've created a quick benchmark (using BenchmarkDotNet) for the class (see the benchmark here) and here are the results for it:
We can see that the performance of
FixedTypeObjectKeyHashtable
is pretty comperable toFixedTypeKeyHashtable
. Slight slowdown is expected due to hash combination.Built in benchmarks
I've fixed and ran the built in benchmarks both on


master
and on my branch. There is a slight performance degradation during container building due to a bit more complex registration. Resolving is unchanged (the benchmarks show that in my branch the resolving is a bit faster, but I think it's inside a margin of error).