I am getting started with Hangfire as a console app. When I start this I want to add an additional background process. I am using the SqlServerStorage.
private static void Main(string[] args) {
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, cb) => ConfigBuilder(cb, args))
.ConfigureServices((ctx, svcColl) => ConfigureServices(svcColl, ctx.Configuration))
.ConfigureLogging(Configurelogging)
.Build()
.Run();
}
private static void ConfigureServices(IServiceCollection services, IConfiguration cfg) {
var dbcs = cfg.GetValue<string>("ConnectionStrings:DB");
_ = services.AddHangfire(gc => {
_ = gc
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(dbcs);
});
_ = services.AddHangfireServer(JobStorage.Current, new[] { new MyProcess { } });
}
The AddHangfireServer
call throws an exception : 'Current JobStorage instance has not been initialized yet.
which makes sense in this case. How do I get this process tied in so it runs in the background?