Tip for anyone trying to run Hangfire server in a windows service with .net core

recurring
Tags: #<Tag:0x00007f499f648d00>

#1

Maybe the docs should be updated for this type of scenario:
Say you have a working .net core web app and have several class libraries that are configured through dependency injection. Using hangfire is relatively easy to setup and configure AS LONG AS you are setting both the server and client up within the web app itself. Once you venture down the path of setting up the server to live within a windows server, things get sticky. Maybe I should write a blog post about this, but the net sum of it is - this can be done, but its much simpler if you host the asp.net core runtime within your windows service. What this gives you is the WebHostBuilder, which lets you setup the dependencies in the same way as they were in the web app. I’d like to see an example with the Generic HostBuilder, as I couldn’t get anything working with dependencies.
Here is an example on the Msft website hosting asp.net core in a windows service.
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.2&tabs=visual-studio