Understanding VContainer #499
Replies: 3 comments 4 replies
-
Okay I just had to read the docs more carefully. Inversing builder.Register.As.WhenInjectedInto just becomes Register().WithParamater(T); |
Beta Was this translation helpful? Give feedback.
-
Hey Simon, I recently start to use Vcontainer do you know how to resolve registered objects at runtime with an API call from the lifetime scope instead of instantiating that class and its dependencies again?
Injecting dependencies every time we instantiate an object feels like it breaks the point of IoC . Can we resolve the dependency of a registered class at runtime with a direct call to the resolver? ex |
Beta Was this translation helpful? Give feedback.
-
Thanks for the advice. I don't really try to make a brand new game framework based solely on VContainer. I just want to integrate IoC into my existing game framework. For doing this, I can either write my own service locator or use one of the existing DI frameworks. So I decided to use Vcontainer which is look simple enough(less complex) to integrate with my framework compared to other DI frameworks( Zenject ). |
Beta Was this translation helpful? Give feedback.
-
I was trying to add some functionality to VContainer.
Specifically something similar to Zenject's .WhenInjectedInto() attribute. This creates a conditional binding.
Digging through the code, it looks like the Registry is a Dictionary with the Binding Type as the Key.
This mean a type can only ever be bound once in the registry, meaning you couldn't do.
ideally these would be two separate bindings, and I guess the WhenInjectedInto would need to resolve after as well.
I have a feeling if the dictionary key was changed from (Type) to (Type, ConditionalArgs) then you would be able to do this.
Then it would do something like:
So maybe it's possible to extend this to conditionals in general where you pass in an action:
Beta Was this translation helpful? Give feedback.
All reactions