title: Caliburn Micro and Castle Windsor Bootstrapper - Register View Model classes in bootstrapper
body: <p>I use Castle Windsor bootstrapper in my WPF app. I tried register view model classes to windsor container.</p>
  
  <p>I have all view models classes in namespace sample.viewmodels</p>
  
  <p>So I tried this:</p>
  
  <pre><code>        _windsorContainer.Register(AllTypes.FromAssembly(GetType().Assembly)
                                         .Where(x =&gt; x.Namespace.EndsWith("ViewModels"))
                                         .Configure(x =&gt; x.LifeStyle.Is(LifestyleType.Singleton)));
  </code></pre>
  
  <p>Or this way for register view model classes to container:</p>
  
  <pre><code>    _windsorContainer.Register(AllTypes.FromAssembly(GetType().Assembly)
                                     .Where(x =&gt; x.Namespace.Equals("Sample.ViewModels"))
                                     .Configure(x =&gt; x.LifeStyle.Is(LifestyleType.Singleton)));
  </code></pre>
  
  <p>This way doesn't work.  I don’t why. <code>MainViewModel / ChildViewModel</code> property is null.</p>
  
  <p>If I use this style it works good.</p>
  
  <pre><code>        ////Shell
          _windsorContainer.Register(
              Component.For&lt;IShellViewModel&gt;()
                  .ImplementedBy&lt;ShellViewModel&gt;()
                  .LifeStyle.Is(LifestyleType.Singleton));
  
          //Main screen
          _windsorContainer.Register(
              Component.For&lt;IMainViewModel&gt;()
                  .ImplementedBy&lt;MainViewModel&gt;()
                  .LifeStyle.Is(LifestyleType.Singleton));
  
          //Child screen
          _windsorContainer.Register(
              Component.For&lt;IChildViewModel&gt;()
                  .ImplementedBy&lt;ChildViewModel&gt;()
                  .LifeStyle.Is(LifestyleType.Singleton));
  </code></pre>
  
  <p>What is bad in first case?</p>
  
  <p>Here I have view models:</p>
  
  <pre><code>namespace Sample.ViewModels
  {
      public interface IShellViewModel
      {}
  
      public class ShellViewModel : Conductor&lt;IScreen&gt;.Collection.AllActive,
          IShellViewModel
      {
          public IMainViewModel MainViewModel { get; set; }
  
          public IChildViewModel ChildViewModel { get; set; }
  
          protected override void OnInitialize()
          {
              DisplayName = "Castle Windsor Boostraper";
              base.OnInitialize();
          }
      }
  
      public interface IMainViewModel : IScreen
      {
          void SayHello();
      }
  
      public class MainViewModel : Screen, IMainViewModel
      {
          public void SayHello()
          {
              MessageBox.Show("Hello from MainViewModel");
          }
      }
      public interface IChildViewModel : IScreen
      {
          void SayHello();
      }
  
      public class ChildViewModel : Screen, IChildViewModel
      {
          public void SayHello()
          {
              MessageBox.Show("Hello from ChildViewModel");
          }
      }
  }
  </code></pre>
  
  <p><strong>EDITED:</strong></p>
  
  <p>I little update registration part:</p>
  
  <pre><code>        _windsorContainer.Register(AllTypes.FromAssembly(GetType().Assembly)
                                         .Pick()
                                         .WithService.DefaultInterface()
                                         .Configure(x =&gt; x.LifeStyle.Is(LifestyleType.Singleton)));
  </code></pre>
  
  <p>It work but I am not sure if this is best way.</p>