title: Unity DI in Windows Forms with child forms
body: <p>I am using Unity DI in a windows forms application.  It is working so far resolving dependencies to the main form in program.cs like this:</p>
  
  <pre><code>    static void Main()
  {
      IUnityContainer container = new UnityContainer();
      container.AddNewExtensionIfNotPresent&lt;EnterpriseLibraryCoreExtension&gt;();
      container.RegisterType&lt;IAccountService, AccountService&gt;();
      container.RegisterType&lt;IAccountRepository, AccountRepository&gt;();
  
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(container.Resolve &lt;MainForm&gt;());
  }
  </code></pre>
  
  <p>My problem is when my MainForm tries creates a child form:</p>
  
  <pre><code>    ChildForm childForm = new ChildForm();
      childForm.Show();
  </code></pre>
  
  <p>I am getting an error because I'm trying to use constructor injection and I'm not passing in the constructor arguments. I also tried using setter injection with the [Dependency] attribute but that didn't work either.  How should I accomplish this?  I could have my main form have all the dependencies and pass the required objects to the child forms, but if I end up having many child forms then the main form would be messy.</p>