title: WPF Prism.Unity - how to construct a ViewModel using named dependency injection
body: <p>Using <code>Prism</code> 7.1, I can register two named dependencies:</p>
  
  <pre><code>containerRegistry.Register&lt;ICustomersService, CustomersFakeService&gt;("One");
  containerRegistry.Register&lt;ICustomersService, CustomersFakeService&gt;("Two");
  </code></pre>
  
  <p>Now - how can I use any of them in <code>ViewModel</code> constructor?</p>
  
  <pre><code>public CustomersViewModel(ICustomersService customersService, EventAggregator eventAggregator)
  </code></pre>
  
  <p>throws an exception:</p>
  
  <blockquote>
    <p>Resolution of the dependency failed, type =
    'WPFPrismDI.ViewModels.CustomersViewModel', name = '(none)'. Exception
    occurred while: while resolving. Exception is:
    InvalidOperationException - The current type,
    WPFPrismDI.Services.ICustomersService, is an interface and cannot be
    constructed. Are you missing a type mapping?
    ----------------------------------------------- At the time of the exception, the container was:    Resolving
    WPFPrismDI.ViewModels.CustomersViewModel,(none)   Resolving parameter
    'customersService' of constructor
    WPFPrismDI.ViewModels.CustomersViewModel(WPFPrismDI.Services.ICustomersService
    customersService, Prism.Events.EventAggregator eventAggregator)
        Resolving WPFPrismDI.Services.ICustomersService,(none)</p>
  </blockquote>
  
  <p>My implementation of the service:</p>
  
  <pre><code>public interface ICustomersService
  {
      ObservableCollection&lt;CustomerModel&gt; CustomerGetAll();
  }
  
  public class CustomersDBService : ICustomersService
  {
      public ObservableCollection&lt;CustomerModel&gt; CustomerGetAll()
      {
          ObservableCollection&lt;CustomerModel&gt; returnValue = new ObservableCollection&lt;CustomerModel&gt;();
  
          returnValue.Add(new CustomerModel() { NameFirst = "DB", });
  
          return returnValue;
      }
  }
  </code></pre>