You can find more details and documentation about Hangfire at Hangfire.io. Really, there are only three steps to setting up Hangfire with ASP.NET Core:

Tell ASP.NET Core about Hangfire Tell Hangfire which database to use Start firing off background jobs

In Startup.cs, in the ConfigureServices method:

services.AddHangfire(x => x.UseCouchbaseStorage(configuration, "familyPhotos_hangfire"));

Then, in Startup.cs, in the Configure method:

app.UseHangfireServer();

I’m using Couchbase in this example, but there are options for SQL Server and other databases too. I happen to think Couchbase is a great fit, because it can easily horizontally scale to grow with your ASP.NET Core deployments. It also has a memory-first architecture for low latency storage/retrieval of job data. Generally speaking, even if you use SQL Server as your "main" database, Couchbase makes a great companion to ASP.NET or ASP.NET Core as a cache, session store, or, in this case, backing for Hangfire.

The configuration variable is to tell Hangfire where to find Couchbase:

var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri("http://localhost:8091") } }; configuration.SetAuthenticator(new PasswordAuthenticator("hangfire", "password"));

(In my case, it’s just running locally).

Steps 1 and 2 are down. Next, step 3 is to create some background jobs for Hangfire to process. I’ve created an ASP.NET Core app to assist me in the cataloging of all my family photographs. I want my application to scan for new files every hour or so. Here’s how I create that job in Hangfire:

RecurringJob.AddOrUpdate("photoProcessor", () => processor.ProcessAll(), Cron.Hourly);

Note that I didn’t have to implement an IJob interface or anything like that. Hangfire will take any expression that you give it (at least, every expression that I’ve thrown at it so far).

Step 3 done.