Asp.Net Core 2.1 Dependency Injection without JobActivator

recurring
Tags: #<Tag:0x00007fa53b4104c8>

#1

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.


#2

Hangfire already has an implementation of JobActivator for ASP.Net Core, and (AFAIK), the helpers you’re using already configures the default job activator.


#3

Thank you. It was strange seeing all these examples and documentation but never found the answer for why it was not needed.