title: How to create an IdentityDbContext with a variable connection string?
body: <p>Having my own implementation of the IdentityDbContext, I would like it to be able to connect to a custom database according to the user's choice. So I have created 2 constructors for both default database and user selected database.</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("Users", throwIfV1Schema: false)
      {
          //Aici am adaugat
          Configuration.ProxyCreationEnabled = true;
          Configuration.LazyLoadingEnabled = true;
      }
  
      public ApplicationDbContext(String connectionName)
          : base(connectionName, throwIfV1Schema: false)
      {
          //Aici am adaugat
          Configuration.ProxyCreationEnabled = true;
          Configuration.LazyLoadingEnabled = true;
      }
  }
  </code></pre>
  
  <p>My problem is now the way I would bring the custom <code>connectionName</code> into the class.</p>
  
  <p>The constructor is called in this method:</p>
  
  <pre><code>public static string conn;
  public static ApplicationDbContext Create()
          {
              if(conn == null)
                  return new ApplicationDbContext();
              else
                  return new ApplicationDbContext(conn);
          }
  </code></pre>
  
  <p>Using session variables is impossible because in this context <code>HttpContext.Current</code> is null. Adding a string argument to the <code>Create</code> method is also impossible, because right in the <code>Startup</code> class, before any user selection, Owin decides on using a default database:</p>
  
  <pre><code>app.CreatePerOwinContext(() =&gt; ApplicationDbContext.Create());
  </code></pre>
  
  <p>Even passing an argument there would not help because it wouldn't have been chosen by the user.</p>
  
  <p>What can I do about it?</p>
  
  <p>Thank you very much!</p>