title: How to move data across layers (MVC5 + EF6 + DDD)?
body: <p>We have a MVC 5 application using DDD principles. I need to send data from the Base Controller to the Base Repository, so I can log what user executed an operation for auditing purposes. The application structure is: Presentation (MVC 5) &gt; Application (AppService) &gt; Domain (Service) &gt; Infra (Repository). The idea is to keep each layer independent from the other as much as possible.</p>
  <p>In the BaseController I have the logged user from the session, that is accessible to all classes in the presentation layer:</p>
  <pre><code>    public ProfileApp ProfileApp
      {
          get { return Session?[Constantes.Session.PROFILE] == null ? CreateProfileApp() : (ProfileApp)Session[Constantes.Session.PROFILE]; }
          set { Session[Constantes.Session.PROFILE] = value; }
      }
  </code></pre>
  <p>How can I get that information to the repository, in the Add method, declared as below:</p>
  <pre><code>public class RepositoryBase&lt;TEntity&gt; : IDisposable, IRepositoryBase&lt;TEntity&gt; where TEntity : BaseIdentity
  {
      protected VGPartnerDBContext _Db;
      protected DbSet&lt;TEntity&gt; _DbSet;
  
      public RepositoryBase(VGPartnerDBContext p_VGPartnerDBContext)
      {
          _Db = p_VGPartnerDBContext;
          _DbSet = _Db.Set&lt;TEntity&gt;();
      }
  
      protected virtual T Add&lt;T&gt;(T obj) where T: BaseIdentity
      {
  
          return _Db.Set&lt;T&gt;().Add(obj);
      }
      
      public virtual TEntity Add(TEntity obj)
      {
          return Add&lt;TEntity&gt;(obj);
      }
  </code></pre>