Issue registering generic types with Autofac in ASP.NET Core
<p>I'm a relatively new user of both Autofac and ASP.NET Core.  I've recently ported a small project from a 'classic' ASP.NET WebAPI project to ASP.NET Core.  I am having trouble with Autofac, specifically in registration of generic types.</p>

<p>This project uses a Command pattern, each command handler is a closed generic like</p>

<pre><code>public class UpdateCustomerCommandHandler: ICommandHandler&lt;UpdateCustomerCommand&gt;
</code></pre>

<p>These command handlers are injected into the controllers like:</p>

<pre><code>readonly private ICommandHandler&lt;UpdateCustomerCommand&gt; _updateCustomerCommand;
public ValuesController(ICommandHandler&lt;UpdateCustomerCommand&gt; updateCustomerCommand)
{
    _updateCustomerCommand = updateCustomerCommand;
}
</code></pre>

<p>Autofac is configured (partially) as:</p>

<pre><code> var builder = new ContainerBuilder();
 var assemblies = AppDomain.CurrentDomain.GetAssemblies();
 //This doesn't seem to be working as expected.
 builder.RegisterAssemblyTypes(assemblies)
     .As(t =&gt; t.GetInterfaces()
         .Where(a =&gt; a.IsClosedTypeOf(typeof(ICommandHandler&lt;&gt;)))
         .Select(a =&gt; new KeyedService("commandHandler", a)));
</code></pre>

<p>The above does not seem to be registering the generic as expected.  If I use the below method for registration, it works well.</p>

<pre><code> builder.RegisterType&lt;UpdateCustomerCommandHandler&gt;().As&lt;ICommandHandler&lt;UpdateCustomerCommand&gt;&gt;();
</code></pre>

<p>When I say "It doesn't work", what I mean is that when attempting to instantiate the controller, I get "InvalidOperationException: Unable to resolve service for type 'BusinessLogic.ICommandHandler`1[BusinessLogic.UpdateCustomerCommand]' while attempting to activate 'AutoFac_Test.Controllers.ValuesController'."</p>

<p>This worked well in the Full WebAPI version of this project, but not after recreating it in ASP.NET Core.  To be clear, this was working perfectly well before porting to ASP.NET Core.</p>

<p>Here is a link to the code that I've used to recreate this issue:
<a href="https://dl.dropboxusercontent.com/u/185950/AutoFac_Test.zip" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/185950/AutoFac_Test.zip</a></p>

<p>**** EDIT AFTER SOLUTION DISCOVERED ****</p>

<p>There was nothing in fact wrong with my Autofac configuration and certainly not Autofac itself.  What had happened was that I had renamed the output of my dependent assemblies in an effort to make the assembly scanning stuff (replacing of <code>AppDomain.CurrentDomain.GetAssemblies()</code> more elegant, however I never modified the dependencies of the API project to reference the new assemblies.  So Autofac was scanning the correctly loaded assemblies which happened to be the older versions, which did not contain the interfaces and implementations I expected...</p>