title: Pass Autofac container to WPF UserControl
body: <p>I am using autofac to resolve Views and ViewModels in a WPF application. IComponentContext is being passed into the View automatically.</p>
  
  <p>An example:</p>
  
  <pre><code>    public BusinessAuto(int proposedCoverageId, IComponentContext componentContext)
      {
          DataContext = componentContext.Resolve&lt;BusinessAutoViewModel&gt;(new TypedParameter(typeof(Int32), proposedCoverageId));
          InitializeComponent();
      }
  </code></pre>
  
  <p>In the XAML for this view there are UserControls being created that have their own ViewModels.  An example:</p>
  
  <pre><code>&lt;userControl:AdditionalCoveragesControl Margin="0,10"/&gt;
  </code></pre>
  
  <p>Autofac is not creating the UserControl (the View is) so Autofac cannot inject dependencies into the UserControl's constructor.</p>
  
  <p><strong>How can I get the reference to IComponentContext into a UserControl that is declared in the initial View's XAML?</strong></p>
  
  <p>I feel that I either need Autofac to somehow create my UserControl, that I need to revert to the discouraged Global static container (ick), or I have to use a DependencyProperty to pass the container down (also ick).</p>