title: How to register many for open generic in Autofac
body: <p>I'm new to <strong>Autofac</strong> (not to <strong>DI</strong>). Here is the situation:</p>
  
  <p>I have these interfaces:</p>
  
  <pre><code>public interface IQuery&lt;out TResult&gt; : IQuery { }
  
  public interface IQueryHandler&lt;in TQuery, out TResult&gt; where TQuery : IQuery&lt;TResult&gt; {
      TResult Handle(TQuery query);
  }
  </code></pre>
  
  <p>and there is a lot of implementation of them in my solution:</p>
  
  <pre><code>class GetPersonQuery : IQuery&lt;PersonModel&gt; { }
  class GetPersonQueryHandler : IQueryHandler&lt;GetPersonQuery, PersonModel&gt; { }
  
  class GetArticleQuery : IQuery&lt;ArticleModel&gt; { }
  class GetArticleQueryHandler : IQueryHandler&lt;GetArticleQuery, ArticleModel&gt; { }
  
  class GetSomethingQuery : IQuery&lt;IEnumerable&lt;SomeModel&gt;&gt; { }
  class GetSomethingQueryHandler : IQueryHandler&lt;GetSomethingQuery, IEnumerable&lt;SomeModel&gt;&gt; { }
  </code></pre>
  
  <p>and so on. I'm currently registering them like this:</p>
  
  <pre><code>builder.RegisterType&lt;GetPersonQueryHandler&gt;()
      .As&lt;IQueryHandler&lt;GetPersonQuery, PersonModel&gt;&gt;();
  
  builder.RegisterType&lt;GetArticleQueryHandler&gt;()
      .As&lt;IQueryHandler&lt;GetArticleQuery, ArticleModel&gt;&gt;();
  
  builder.RegisterType&lt;GetSomethingQueryHandler&gt;()
      .As&lt;IQueryHandler&lt;GetSomethingQuery, SomeModel&gt;&gt;();
  
  // blah blah blah
  </code></pre>
  
  <p>As you can see, I have a many same registrations. In <code>SimpleInjector</code> (which I was using before), I could register all of them by a single line:</p>
  
  <pre><code>container.RegisterManyForOpenGeneric(
      typeof(IQueryHandler&lt;,&gt;),
      AppDomain.CurrentDomain.GetAssemblies());
  </code></pre>
  
  <p>Is it possible to do this stuff in <strong>Autofac</strong>?</p>