Have any service related stuff implement IHostedService
, so it is easy to deploy it in all kinds of processes:
- console to test
- windows service
- ASP.NET Core service
- Linux host application
Peter Groenewegen ([WayBack] pgroene (Peter Groenewegen) · GitHub; [WayBack] { Think Rethink }) has some great examples and blog articles at [WayBack] IHostedService – { Think Rethink }:
- [WayBack] ASP.NET Core background processing with IHostedService – { Think Rethink }: Run background processes with the IHostedService and how to inject your services with dependency injection
- [WayBack] Application Shutdown in ASP.NET Core with IApplicationLifetime – { Think Rethink }: Learn how to gracefully handle Application Shutdown in ASP.NET Core by looking at the handling of flushing the application insights messages when asp.net core exits
- [WayBack/Archive.is] Run scheduled background tasks in ASP.NET Core – { Think Rethink }: In the previous blog post called background tasks with ASP.NET Core using the IHostedService Peter described how to use the IHostedInterface for background tasks. In this post, we continue on this …
- [WayBack] GitHub – pgroene/ASPNETCoreScheduler
- [WayBack] Injecting a Scoped service into IHostedService – { Think Rethink }: Cannot consume scoped service ‘IScoped’ from singleton ‘Microsoft.Extensions.Hosting.IHostedService’.
- [WayBack] Hosting services in .NET Core console application – { Think Rethink }: Building .NET Core console applications with IHost and HostBuild to take advantage of IHostedService, graceful shutdown, dependency injection, logging, configuration and more.
Background information:
-
- [WayBack] Background tasks with hosted services in ASP.NET Core | Microsoft Docs: Learn how to implement background tasks with hosted services in ASP.NET Core.
- [WayBack] IHostedService Interface (Microsoft.Extensions.Hosting) | Microsoft Docs: Defines methods for objects that are managed by the host. (methods StartAsync(CancellationToken), StopAsync(CancellationToken))
- [WayBack] GitHub – quartznet/quartznet: Quartz Enterprise Scheduler .NET
- [WayBack] GitHub – atifaziz/NCrontab: Crontab for .NET
- [WayBack] ASP.NET Core Architect David Fowler’s hidden gems in 2.1 – Scott Hanselman
- [WayBack] Implementing IHostedService in ASP.NET Core 2.0 – Steve Gordon
Exploring an example of using the new IHostedService interface from ASP.NET Core 2.0 to run background tasks that shut down when our WebHost shuts down.
[WayBack] GitHub – stevejgordon/IHostedServiceSample: A sample 2.0 preview 2 API which implements IHostedService
- [WayBack] Having Fun with the .NET Core Generic Host · Jonathan’s Blog
As ASP.NET developers we’re fairly used to hosting our code inside Internet Information Services (IIS). However, since ASP.NET Core is cross-platform, hosting inside IIS isn’t always an option. For that reason, the hosting model for ASP.NET Core applications looks quite a bit different. Of course, we can still host our code in IIS, but we also have the option to use Kestrel and run as a standalone application.This new hosting model is visible in code through the WebHostBuilder API from Microsoft.
- [WayBack] Kestrel web server implementation in ASP.NET Core | Microsoft Docs
Learn about Kestrel, the cross-platform web server for ASP.NET Core.
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that’s included by default in ASP.NET Core project templates.
Kestrel supports the following features:
- HTTPS
- Opaque upgrade used to enable WebSockets
- Unix sockets for high performance behind Nginx
Kestrel is supported on all platforms and versions that .NET Core supports.
- [WayBack] Kestrel web server implementation in ASP.NET Core | Microsoft Docs
- [WayBack] Implementing background tasks in .NET Core 2.x webapps or microservices with IHostedService and the BackgroundService class – Cesar de la Torre [Microsoft] – BLOG
- [WayBack] Thread by @Nick_Craver: “This is a good addition to .NET – the Stack Overflow scheduler is based on IHostedService, and we have a lot of other plans for it too. Some […]” #AspNetCore
- [WayBack] Background tasks with hosted services in ASP.NET Core | Microsoft Docs: Learn how to implement background tasks with hosted services in ASP.NET Core.