Difference between AddHangfire and AddHangfireServer

Source code looks like AddHangfire adds the service registration, while AddHangfireServer registers hosted service. This sounds like they are completely 2 things and should be called both. However AddHangfireServer isn’t necessary in order to make it work. So what’s the recommended way to set up here?

The recommended way to set things up depends on what you want to do. AddHangfire allows you to configure everything, allowing you to enqueue and run jobs from the app you call it from. AddHangfireServer registers just the bits that run jobs in the background, so you might use this when you create a headless “job execution service” as it is focused solely on running jobs rather than getting input/parameters from the user.

In our app, each server calls AddHangfire but only starts a Hangfire server if configured to do so. Each web server registers a BackgroundJobClient so it can submit jobs to queues without executing them. We designate one server to run jobs, so that server calls UseHangfireServer during its Configure call.