163
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
Deployment considerations and takeaways
It is important to note that the way you deploy your ASP.NET Core
WebHost
or .NET
Host
might
impact the final solution. For instance, if you deploy your
WebHost
on IIS
or a regular Azure App
Service, your host can be shut down because of app pool recycles. But if you are deploying your host
as a container into an orchestrator like Kubernetes, you can control the assured number of live
instances of your host.
In addition, you could consider other approaches in the cloud especially made
for these scenarios, like Azure Functions. Finally, if you need the service to be running all the time and
are deploying on a Windows Server you could use a Windows Service.
But even for a
WebHost
deployed into an app pool, there are scenarios like repopulating or flushing
application’s in
-memory cache that would be still applicable.
The
IHostedService
interface provides a convenient way to start background tasks in an ASP.NET
Core web application (in .NET Core 2.0 and later versions) or in any process/host (starting in .NET Core
2.1 with
IHost
). Its main benefit is the opportunity you get with the graceful
cancellation to clean-up
the code of your background tasks when the host itself is shutting down.
Dostları ilə paylaş: