dotnet-hosted-services

Installation
SKILL.md

.NET hosted services - background work on the generic host

This skill owns the host a long-running task runs inside: how the work is registered, which base type to derive from, what happens when it throws, how it reaches a scoped dependency, how it loops, and how it stops cleanly. It stops at the host boundary. When the work is driven by a broker - a queue consumer, an outbox relay, a saga - the delivery contract, idempotency, and retry policy are dotnet-messaging; this skill only owns the host process those consumers happen to live in. The HTTP service around an in-process background task is dotnet-web-backend. The async, Task, and Channel<T> language mechanics are csharp. Concurrency correctness for a worker loop - awaiting without deadlock, threading a cancellation token to the leaves, SemaphoreSlim / Interlocked for shared state, and bounded parallelism - is references/concurrency.md. Floor is .NET 8 / C# 12; anything newer is marked optional.

The two host shapes

There is one hosting model and two ways to enter it. Pick by what the process is.

A standalone worker - no HTTP surface, just background work - is a worker binary. The project uses the Microsoft.NET.Sdk.Worker SDK and Host.CreateApplicationBuilder:

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<IngestWorker>();
var host = builder.Build();
host.Run();

Host.CreateApplicationBuilder (the post-.NET-6 linear builder, preferred over the old CreateDefaultBuilder/callback style) wires configuration, logging, and DI the same way the web host does - the hosted services you register run under the same lifecycle.

Installs
15
GitHub Stars
1
First Seen
Jun 21, 2026
dotnet-hosted-services — envoydev/claude-stack