What is the best way to transparently inject dependencies (using IOC container) to user controls in WPF?
I assume that user controls are part of XAML for the window or other user controls. Also I think parent (whoever it is) should not be responsible for this. Solution for manually injecting dependencies from parent looks not clean enough for me. I want to avoid managing the dependencies of my components explicitly as it voilates the idea of IOC.
Is any event which is raised when logical tree is being created so I can intercept it and inject my dependencies?
EDIT: by dependencies I also mean ViewModel, Controller, Presenter (whatever pattern is used)
Thanks, Andrey
The best way to deal with dependencies in WPF is by following the MVVM pattern.
In short, you don't inject dependencies directly into User Controls (View), but rather into their DataContext (ViewModel).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With