Host configuration, background work and Windows Service deployment from Regira.System.Hosting. These apply to any host, including an ASP.NET Core application.
Bind from appsettings.json under "Hosting":
| Property | Type | Default | Description |
|---|---|---|---|
ServiceName |
string? |
null |
App / Windows Service display name |
Mode |
string |
"Production" |
Hosting mode (inherited from HostOptions; see HostingModes) |
LocalPort |
int? |
null |
Override listening port |
SelfHosting |
bool |
false |
Flags the app as self-hosted (e.g. Kestrel / Windows Service) |
EnableSwagger |
bool |
true |
Toggle Swagger UI |
EnableCors |
bool |
false |
Toggle CORS |
EnableHttps |
bool |
false |
Toggle HTTPS redirect |
RoutePrefix |
string? |
null |
API route prefix |
{
"Hosting": {
"ServiceName": "MyApi",
"LocalPort": 5000,
"EnableSwagger": true,
"EnableCors": false,
"RoutePrefix": "api/v1"
}
}
var builder = WebApplication.CreateBuilder();
builder.Host.UseWebHostOptions();
Queue and execute long-running work without blocking requests.
services.UseBackgroundQueue();
// In a controller
public IActionResult StartExport([FromServices] IBackgroundTaskQueue queue)
{
queue.QueueBackgroundWorkItem(async token =>
{
await GenerateReport(token);
});
return Accepted();
}
Typed tasks carry progress and a status you can poll:
services.UseBackgroundQueue<ReportTask>();
// inject IBackgroundQueueManager<ReportTask>
var task = queueManager.Execute<string>(async (sp, t) =>
{
t.SetProgress(0.5);
return await GenerateReport(sp, t.Id);
});
Work items run one at a time. One that throws is logged and the next one runs; a typed task records the exception and ends with status Error. The queue is unbounded and the task manager keeps every typed task until it is removed, so an app that queues per request removes finished tasks (Remove(id) after the result is read, or Clear()).
A worked end-to-end example — enqueue from a controller, then poll the task’s status — is in the Web examples.
using Microsoft.Extensions.Hosting.WindowsServices; // WindowsServiceHelpers
var builder = WebApplication.CreateBuilder(args);
if (WindowsServiceHelpers.IsWindowsService()) builder.Host.UseWindowsService();
var app = builder.Build();
app.AddWindowsServiceInstaller(new WindowsServiceOptions
{
ServiceName = "MyApi",
InstallFilename = "install.bat",
UninstallFilename = "uninstall.bat"
});
Generates install.bat / uninstall.bat scripts using sc.exe. The installer only writes the scripts: the host must
also call UseWindowsService() to run as a service. Microsoft.Extensions.Hosting.WindowsServices comes with
Regira.System.Hosting.
WebHostOptions, background task queues, Windows Service installer.csproj filesApache License 2.0 — this package contains no license validation and no runtime limits. See LICENSE. A few companion packages are commercially licensed with a free tier; see the licensing overview.