I am trying to configure a simple service that will call a method every hour to send emails out. I configured my startup as such:
public void ConfigureServices(IServiceCollection services)
{
services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("ASP_NetPractice")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddScoped<ISendEmail, SendEmail>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//other code
app.UseHangfireServer();
app.UseHangfireDashboard();
RecurringJob.AddOrUpdate<ISendEmail>((email) => email.CheckReminder(), Cron.Hourly);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
In all the examples I’ve been reading including the documentation, I saw reference to JobActivator to implement IOC. Yet my above code works without having to configure any such thing. Is it required to implement for it to function the right way? Am I incorrect in the approach I am taking?
Does the built in services.AddHangfire() take care of this? Any help would be appreciated.