AFract
AFract

Reputation: 9700

Windows service that could also be hosted in Azure (or Azure component that could work as a Windows Service)

We are working on a MVC Core project which requires to be hostable either on Azure, either on IIS (on premise), depending of the final customer wills. Our minimal support level is Windows Server 2012.

Along this project, we need to have a background process that will schedule some specific treatments.

In on premise context, a regular windows service would perfectly fit. But it can't be deployed easily in Azure, apart in a VM as described https://stackoverflow.com/a/36026658/461444

So we would like instead to know if there is a simple solution that can be exploited both as a Windows Service (or something very close), and as an Azure component in a single implementation.

Upvotes: 0

Views: 183

Answers (2)

Alex
Alex

Reputation: 18556

How about using the background service feature of ASP.NET Core?

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.2&tabs=visual-studio

https://learn.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/background-tasks-with-ihostedservice

If you configure your website to keep running (Azure App Service: "Always On") your workload should work just fine. Just be aware of how many instances the AppService runs on and if you need to coordinate the instances. When in doubt, you can always just create two ASP.NET Applications, where one is just responsible for handling the background work. This way you can control the scaling and lifetime of each service independently.

Asp.NET Core 2.1 HostedService - keep running on Azure

IWebHost and IHost

Upvotes: 1

Casey Crookston
Casey Crookston

Reputation: 13965

I would create three projects:

  1. A class library that does all of the logic you need. Because it's just a class library, it can then be included in any other project
  2. A Windows Service that does nothing but call the class library from #1
  3. An Azure Function that does nothing but call the class library from #1

The Windows Service can easily be deployed on an on-prem IIS server.
The Azure Function can easily be deployed into Azure without the need for an Azure VM.

(Side note: the thread you pointed to is three years old. I don't know if Azure Functions existed at the time.)

Upvotes: 1

Related Questions