title: Registering and using forms with Windsor
body: <p>I'm trying to figure out how to use NHibernate/Windsor in a windows forms application. I have this in my main method:</p>
  
  <pre><code>static void Main()
  {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
  
      var container = new WindsorContainer();
  
      var containerAdapter = new WindsorContainerAdapter(container);
      var MarketingDatabaseSessionFactory = new NHibernate.Cfg.Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.config")).BuildSessionFactory();
  
      NCommon.Configure.Using(containerAdapter)
          .ConfigureState&lt;DefaultStateConfiguration&gt;(stateConfig =&gt;
                                                     stateConfig.UseCustomSessionStateOf&lt;HttpSessionState&gt;())
          .ConfigureUnitOfWork&lt;DefaultUnitOfWorkConfiguration&gt;(x =&gt;
                                                               x.AutoCompleteScope())
          .ConfigureData&lt;NHConfiguration&gt;(config =&gt; config.WithSessionFactory(() =&gt; MarketingDatabaseSessionFactory)
              .WithDistinctResults());
  
  
  
      container.AddComponent("main", typeof(Form1));
  
      container.Register(AllTypes.FromAssemblyNamed("ProductManager.Services").BasedOn(typeof(IService)).WithService.Select((t, baseType) =&gt; t.GetInterfaces()));
  
      ServiceLocator.SetLocatorProvider(() =&gt; new WindsorServiceLocator(container));
  
      Form1 mainForm = container.Resolve&lt;Form1&gt;();
      Application.Run(mainForm);
  }
  </code></pre>
  
  <p>That works great, the DI works for all my services and for my main form. My question is how do I move forward from there? I have the first form working but how do I inject dependencies into the other forms and controls? In MVC there is a way to register all your controllers, I'm looking for something similar with forms, but I'm confused because you have to explicitly instantiate the forms. So, even if I register each form one by one, I don't know how I would shoot off a child form or control without resolving everything myself which misses the point.</p>