.NET hosting infrastructure for Windows Services.
$ dotnet add package Microsoft.Extensions.Hosting.WindowsServicesSupports using Windows Services with the hosting infrastructure.
From a Worker Service app created using the Visual Studio template:
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
})
// Configure as a Windows Service
.UseWindowsService(options =>
{
options.ServiceName = "My Service";
})
.Build();
host.Run();
The main types provided by this library are:
Microsoft.Extensions.Hosting.WindowsServiceLifetimeHostBuilderExtensionsMicrosoft.Extensions.Hosting.WindowsServices.WindowsServiceLifetimeMicrosoft.Extensions.HostingSystem.ServiceProcess.ServiceControllerMicrosoft.Extensions.Hosting.WindowsServices is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
81.5M