title: AspIdentiy ApplicationUserManager is Static, how to extend so it participates in my IoC framework?
body: <p>In a new ASPNET MVC application you now get the AspIdentity goodies for free.</p>
  
  <p>There's a harmless little line 'plug in your email service here'.</p>
  
  <p>So I did:</p>
  
  <pre><code>public class EmailService : IIdentityMessageService
  {
      private static My.Services.IEmailService _emailservice;
  
      public EmailService(Insolvency.Services.IEmailService emailservice)
      {
          _emailservice = emailservice;
      }
  
      public Task SendAsync(IdentityMessage message)
      {
          _emailservice.SendEmail(message);
         return Task.FromResult(0);
      }
  }
  </code></pre>
  
  <p>and now the joy:</p>
  
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      private My.Services.IEmailService _emailservice;
  
      public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; store, My.Services.IEmailService emailservice): base(store)        
      {
          _emailservice = emailservice;
      }
  
      public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context)
      {
          var manager = new ApplicationUserManager(new UserStore&lt;ApplicationUser&gt;(context.Get&lt;ApplicationDbContext&gt;()), _emailservice);
         ...
  </code></pre>
  
  <p>as Owin kicks in it calls the Create on ApplicationUserManager in <strong>Startup.Auth.cs</strong>:</p>
  
  <pre><code>public partial class Startup 
     {
      public void ConfigureAuth(IAppBuilder app) 
       {
          ...
          app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
  </code></pre>
  
  <p>and as I'm using AutoFac as my IoC container, in global.asax.cs</p>
  
  <pre><code>builder.RegisterType&lt;My.Services.EmailService&gt;().As&lt;IEmailService&gt;();
  </code></pre>
  
  <p>if the Create method is static so I get:<br>
  <code>_emailService</code> is null</p>
  
  <p>I've looked here:<a href="http://forums.asp.net/post/5293670.aspx" rel="nofollow noreferrer">http://forums.asp.net/post/5293670.aspx</a>, and <a href="https://stackoverflow.com/questions/22924816/how-do-i-create-an-instance-of-usermanager/22924982#22924982">How do i create an instance of UserManager</a> and <a href="https://stackoverflow.com/questions/7777247/using-autofac-to-provide-types-exported-by-static-factory">Using Autofac to provide types exported by static factory</a>.
  but no luck.</p>
  
  <p>If I change:  </p>
  
  <pre><code>private My.Services.IEmailService _emailservice;
  </code></pre>
  
  <p>to be public non-static I feel IoC gods shaking their heads, and I can't build 'object reference required'</p>