Alex Rivera | Logout

How do I inject dependencies to user controls in WPF

Asked 2010-03-09T12:16:56.997
22

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

Edit
Report

1 Answer

1

FrameworkElement has an Initialized event, which you could hook up and inject the dependencies. You should test if it comes early enough for your scenario.

answered 2010-03-09T12:30:29.853

Your Answer