WPF and Inversion of Control: Listing 3.

The App.xaml.cs file.

private static readonly WindsorContainer container = new WindsorContainer();
 
public App()
{
  ConfigureContainer();
}
 
private void ConfigureContainer()
{
  container.AddFacility<ViewActivatorFacility>();
  container.Register(
    AllTypes.FromThisAssembly().BasedOn<IView>()
    .WithService.FromInterface()
    .Configure(c => c.LifeStyle.Is(LifestyleType.Transient)),

    AllTypes.FromThisAssembly().BasedOn<IViewModel>()
    .Configure(c => c.LifeStyle.Is(LifestyleType.Transient))
    );
}

About the Author

Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.