title: How can I resolve a class with 3rd party generic interface by string using autofac
body: <p>There are different classes registered in autofac with same generic interface but using different class models. What I need is to resolve the class with string without knowing the class model. I am not sure if it can easily be achieved. Any suggestions please.  </p>
  
  <p>I am using a console app and I don't know the class model as we receive a string. I have registered all class in the start class but I want to resolve the class without knowing the class model. I don't want to use if else to say if string == "something" then resolve this else if resolve this. I am looking for the best practice.</p>
  
  <pre><code>public TestModel1 { }
  public TestModel2 { }
  
  public interface ICalculator&lt;string, T&gt; {}
  public Impl1: ICalculator&lt;string, TestModel1&gt; {}
  public Impl2: ICalculator&lt;string, TestModel2&gt; {}
  </code></pre>
  
  <p>in Autofac I register like:</p>
  
  <pre><code>builder.Register&lt;Impl1&gt;.As&lt;ICalculator&lt;string, TestModel1&gt;&gt;();
  builder.Register&lt;Impl2&gt;.As&lt;ICalculator&lt;string, TestModel2&gt;&gt;();
  </code></pre>
  
  <p>in Console app I want to do something like:
  container.Resolve by string rather than doing like</p>
  
  <pre><code>if (...) {
  class = container.resolve&lt;ICalculator&lt;string, TestModel1&gt;&gt;()
  } else {
  class = container.resolve&lt;ICalculator&lt;string, TestModel2&gt;&gt;()
  }
  </code></pre>
  
  <p>I want to be able to do something like in console app:</p>
  
  <pre><code>var class = container.resolve&lt;ICalculator&gt;("pass string");
  </code></pre>