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);
});
A worked end-to-end example — enqueue from a controller, then poll the task’s status — is in the Web examples.
var app = WebApplication.Create();
app.AddWindowsServiceInstaller(new WindowsServiceOptions
{
ServiceName = "MyApi",
InstallFilename = "install.bat",
UninstallFilename = "uninstall.bat"
});
Generates install.bat / uninstall.bat scripts using sc.exe.
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.