Check if HangFire.JobStorage is instantiated
You could use the Hangfire.JobStorage.Current
static property itself to check Hangfire storage configuration:
//InvalidOperationException " JobStorage.Current property value has not been initialized"
var storage = JobStorage.Current;
GlobalConfiguration.Configuration.UsePostgreSqlStorage(vaildConnString);
//no exception
storage = JobStorage.Current;
Moreover, you could query a database to test the connection:
JobStorage.Current.GetConnection().GetRecurringJobs();
Considering exceptions, I think that throwing an InvalidOperationException
instead of something like SqlException
is correct. Hangfire core isolated from details of a specific database.