title: C#: Pass Data from Controller to Application Layer to DBContext Layer
body: <p>I would like to pass global custom data from API Level to Application Service, to Repository and DB Context layer, without using parameters in every method.</p>
  
  <p>1) One method is <code>HttpContextAccessor</code>.</p>
  
  <p>Curious if there is any other global parameter embedded in Net Core, or is this the only known strategy? We are passing auditable data, CreateBy, ModifiedDate, but may extend it other properties. We have 100+ apis, application methods, repositories, and trying to prevent passing around a parameter.</p>
  
  <pre><code>_httpContextAccessor.HttpContext.Items["TestKey"] = "SampleData";
  </code></pre>
  
  <p><strong>DBContext:</strong></p>
  
  <pre><code>public class AuditableDbContext: DbContext
  {
      private readonly IHttpContextAccessor _httpContextAccessor;
  
      public AuditableDbContext(DbContextOptions&lt;AuditableDbContext&gt; options, IHttpContextAccessor httpContextAccessor)
          : base(options)
      {
          _httpContextAccessor = httpContextAccessor;
      }
  </code></pre>
  
  <p>Custom Data changes based on application behavior and user interaction. </p>