title: Storing user login data in Business logic layer during session
body: <p>I've got project with dll dependecies like below:
  DataAccessLayer(DAL) &lt;- BusinessLogicLayer(BLL) &lt;- MVC Web App(WEB)</p>
  
  <p>The project needs to connect with database by separated SQL logins (Each SQL login means different App user or in other words already existing database users and passwords will be used as app users/logins). So thre's no way to youse default connection.</p>
  
  <p>I'm passing class "Connection" (Class is defined on BLL so DAL can see it but WEB can't) to my Context class to make connection with database like below:</p>
  
  <pre><code>public class WMSContext : DbContext
  {
      public WMSContext(Connection con)
          : base(con.ContextOption)
      {
      }
  
      public virtual DbSet&lt;Users&gt; Users { get; set; }
      public virtual DbSet&lt;Groups&gt; Groups { get; set; }
      public virtual DbSet&lt;UsersConfig&gt; UsersConfig { get; set; }
      public virtual DbSet&lt;UsersGroup&gt; UsersGroup { get; set; }
      public virtual DbSet&lt;UsersGroupConfig&gt; UsersGroupConfig { get; set; }
      public virtual DbSet&lt;ShipmentVehicles&gt; ShipmentVehicles { get; set; }
      public virtual DbSet&lt;VSHIPMENTS&gt; VSHIPMENTS { get; set; }
      public virtual DbSet&lt;VShipmentsDetails&gt; VShipmentsDetails { get; set; }
  }
  
  
  
  public class Connection
  {
      public string Login { get; private set; }
      public string Password { get; private set; }
      public string Server { get; private set; }
      public string Database { get; private set; }
      public DbContextOptions&lt;WMSContext&gt; ContextOption { get; private set; }
  
      public Connection(string servAddr, string dbName, string login, string pass)
      {
  
          Login = login;
          Password = pass;
          Server = servAddr;
          Database = dbName;
          string connStr = "Data Source = " + servAddr + "; Initial Catalog = "+ dbName + "; Persist Security Info = True; User ID = "+ login + "; Password = "+ pass+ "";
          var optBuild = new DbContextOptionsBuilder&lt;WMSContext&gt;();
          optBuild.UseSqlServer(connStr);
          ContextOption = optBuild.Options;
      }
  }
  </code></pre>
  
  <p>The problem is that the instance of Connection class should be stored somwhere during user session to perform other requests for certain SQL user. My first thought was to assign instance of Connection to Session. Something like below:</p>
  
  <p>Connection = new Connection(){ some login data }
  HttpContext.Session.SetString("Login Data", connection);</p>
  
  <p>but in that case i would have to set DAL dependent to WEB and it not seems to be elegant slolution. Sure i can just extract that Connection class to class liblary that will be shared by all projects but i'm curious if there is some way to store data only in BLL and only temporary and delete them when WEB user session ends?
  Or maybe there is some other way than using Sessions?</p>