title: Autofac factory for a static method
body: <p>I have a component in my application with an interface that looks like this:</p>
  
  <pre><code>interface ILogger : IService
  {
      Task LogAsync(Message message);
  }
  </code></pre>
  
  <p>I need to construct these instances using a static method:</p>
  
  <pre><code>ILogger logger = ServiceProxy.Create&lt;ILogger&gt;(new Uri(...), new ServicePartitionKey(...));
  </code></pre>
  
  <p>This is problematic for my unit testing so I am instantiating with a delegate factory with Autofac:</p>
  
  <pre><code>public class LogConsumer
  {
      private Func&lt;Uri, ServicePartitionKey, ILogger&gt; _logFactory;
      public LogConsumer(Func&lt;Uri, ServicePartitionKey, ILogger&gt; logFactory)
      {
          _logFactory = logFactory;
      }
  
      public async Task MethodThatUsesLogger()
      {
          ILogger logger = _logFactory(new Uri(...), new ServicePartitionKey(...));
  
          await logger.LogAsync(...);           
      }
  }
  </code></pre>
  
  <p>I am registering in Autofac like so:</p>
  
  <pre><code>builder.Register&lt;ILogger&gt;(ctx =&gt; (uri, key) =&gt; ServiceProxy.Create&lt;ILogger&gt;(uri, key));
  </code></pre>
  
  <ul>
  <li>If I need to register 10 different interfaces in the same way, can I do it in one line with generics?</li>
  <li>Is there a way to do this without injecting Func and doing it more like Ninject.Extensions.Factory?</li>
  </ul>