title: Registering async factory in Autofac
body: <p>I have a Wallet class that I get from a repository. I'm trying to properly register both in Autofac so classes using the wallet could have a proper instance injected. The problem is that the repository uses an async method (returning Task). Does Autofac support such cases?</p>
  
  <p>This doesn't work:
  </p>
  
  <pre><code>cb.RegisterType&lt;WalletRepository&gt;()
      .As&lt;IWalletRepository&gt;()
      .SingleInstance();
  cb.Register(async c =&gt; await c.Resolve&lt;IWalletRepository&gt;().CreateAsync(App.WalletPath));
  cb.RegisterType&lt;ViewModel&gt;()
      .AsSelf().
      .SingleInstance();
  </code></pre>
  
  <p>Somewhere in the app I just have:</p>
  
  <pre><code>class ViewModel
  {
      public ViewModel(Wallet wallet)
      {
          //nothing fancy here
      }
  }
  </code></pre>
  
  <p>When calling <code>container.Resolve&lt;ViewModel&gt;()</code> i get an exception saying Wallet is not registered.</p>