I have a project using HangFire for a background job and I need to change the connection string dynamically without needing to change the code manually every time I want to run this job to any customer as I've many customers and many Databases as well I've done this to the normal connection in the startup and DbContext based on this solution and works like a charm Dynamically change connection string in Asp.Net Core
and I want to do the same with the HangFire connection, and this is the code I'm using now
services.AddHangfire(configuration => configuration.UseStorage(
new MySqlStorage("server=127.0.0.1;uid=root;database=0046696-k; Allow User Variables=True",
new MySqlStorageOptions()
{
TransactionIsolationLevel = (System.Transactions.IsolationLevel?)IsolationLevel.ReadCommitted,
QueuePollInterval = TimeSpan.FromSeconds(15),
JobExpirationCheckInterval = TimeSpan.FromHours(1),
CountersAggregateInterval = TimeSpan.FromMinutes(5),
PrepareSchemaIfNecessary = true,
DashboardJobListLimit = 50000,
TransactionTimeout = TimeSpan.FromMinutes(1),
TablesPrefix = "Hangfire"
})));
services.AddHangfireServer();