1
votes

I am used to using Windsor Castle IoC with MVC web applications so I'm a little familiar with registering components and bootstrapping the application.

I am now trying to create my first WPF application and I'm a little lost....

In a typical MVC project I would register all my components in Application_Start in the Global.asax file.
Also, in the Global.asax I would do something like this :

_container = new WindsorContainer();
var myControllerFactory = new MyControllerFactory(_container.Kernel);
ControllerBuilder.Current.SetControllerFactory(myControllerFactory);

In MyControllerFactory which inherits from DefaultControllerFactory I would resolve the Controller given to me, thus all the controllers being used would have their dependencies resolved automatically.

How could I do this in a WPF application ?
I created a class called ContainerBootstrapper that registers my components, and now I'm wondering how I use this in my MainWindow so every time I call a component, it's dependencies are resolved automatically...

1

1 Answers

2
votes

Unlike MVC, WPF does not provide framework for decoupled UI development out of the box. There are several out there (such as Caliburn.Micro which implements the MVVM pattern) that sit on top of WPF and provide integration for a variety of IoC containers as well as other features you may find useful in WPF development.

Alternatively, you will need to manage the container directly. i.e. instantiate and initialise the container in App.xaml.cs or MainWindow.xaml.cs and ensure that new object construction via your container's Resolve() function. If it is a non-trivial app, you will probably want to integrate this into your app's navigation routines.