title: Passing connection string to Entity framework at runt time for each call
body: <p>My Entity framework context is as following </p>
  
  <pre><code> public partial class MyContext : DbContext, IMyContext
  {
      static MyContext()
      {
          System.Data.Entity.Database.SetInitializer&lt;MyContext&gt;(null);
      }
  
      public MyContext()
          : base("Name=MyContext")
      {
      }
  </code></pre>
  
  <p>I am resolving it through autofac in the following way</p>
  
  <pre><code>builder.RegisterType(typeof(MainContext)).As(typeof(DbContext)).InstancePerLifetimeScope();
          builder.RegisterType&lt;MainContext&gt;().As&lt;IMainContext&gt;().InstancePerRequest();
  </code></pre>
  
  <p>This db context gets called in repository layer</p>
  
  <pre><code>#region Fields
  
      private readonly IMyContext _context;
  
      #endregion
  
      #region Constructors and Destructors
  
      public EmployeeRepository(IMyContext context)
      {
          _context = context;
      }
  
      #endregion
  
      public void Create(Employee emp)
      {
          this._context.Employee.Add(emp);
      }
  </code></pre>
  
  <p>Now my issue is , I want to set the connection string dynamically per call. The connection string will be passed through a webapi which i want to pass on to this context. Can anyone help me how can i do that? I am confused about autofac here. Secondly how can i make sure each call sets connection string and does not cache it.</p>