From dece32e3615656d5ac76f2edd9da032c6452d274 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 2 Mar 2019 01:45:24 +0000 Subject: Using dependency injection and scoped services, can setup aggregator job to run without config --- Main/Startup.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Main') diff --git a/Main/Startup.cs b/Main/Startup.cs index 980e110..c077b6b 100644 --- a/Main/Startup.cs +++ b/Main/Startup.cs @@ -32,11 +32,13 @@ namespace Main { options.UseMySQL(Configuration.GetConnectionString("Storage")); }); + services.AddScoped(); + services.AddHangfire(options => options.UseStorage(new MySqlStorage(Configuration.GetConnectionString("Storage")))); services.AddDirectoryBrowser(); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) { + public void Configure(IApplicationBuilder app, IHostingEnvironment env, IAggregatorJob aggregator) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } @@ -51,10 +53,7 @@ namespace Main { app.UseHangfireServer(); app.UseHangfireDashboard(); - RecurringJob.AddOrUpdate( - x => x.Start(Configuration.GetConnectionString("Aggregator")), - Cron.HourInterval(3) - ); + RecurringJob.AddOrUpdate("aggregator", () => aggregator.Start(), Cron.HourInterval(3)); } } } -- cgit v1.2.3-13-gbd6f