title: Registering a different implementation of a service dependant on httpcontext in multi-tenant application Hangfire
body: <p>I have a multi-tenant application where applications are connected to different databases. The application identifies relevant tenants using a connection hash. the connection hash comes from the request header. since HTTPContext is not serializing in Hangifre I need to find a way to pass the connection hash when the service (Repositories) registers.</p>
  <p>I was thinking of adding JobFilterAttribute to pass hash information lying below</p>
  <pre><code>[AttributeUsage(AttributeTargets.Method)]
  public class TenantResolverAttribute : JobFilterAttribute
  {
  
  }
  
  public class TenantResolverFilter : IClientFilter, IServerFilter
  {
      private readonly IHttpContextAccessor _httpContextAccessor;
  
      public TenantResolverFilter(IHttpContextAccessor httpContextAccessor)
      {
          _httpContextAccessor = httpContextAccessor;
      }
      public void OnCreating(CreatingContext filterContext)
      {
          if (filterContext == null) throw new ArgumentNullException(nameof(filterContext));
          var hash = _httpContextAccessor.HttpContext.GetCurrentTenantDatabaseHash();
          filterContext.SetJobParameter(&quot;hash&quot;, hash);
  
      }
  
      public void OnCreated(CreatedContext filterContext)
      {
  
      }
  
      public void OnPerforming(PerformingContext filterContext)
      {
          var hash = filterContext.GetJobParameter&lt;string&gt;(&quot;hash&quot;);
      }
  
      public void OnPerformed(PerformedContext filterContext)
      {
  
      }
  
  }
  </code></pre>
  <p>But the problem is how to pass this information to a method where the entity framework to configure</p>
  <pre><code>  string conenctionString = //need to resolve conenction string using provided hash;
      dbContextOptionsBuilder.UseSqlServer(conenctionString,
          option =&gt;
          {
              option.CommandTimeout(config.SqlCommandTimeout);
              option.EnableRetryOnFailure(3);
          });
  </code></pre>