I am currently hosting an ASP.NET (.NET 5) application in a Windows Service using WebHost and WebHostBuilder.
.NET 6 introduced WebApplication and WebApplicationBuilder. How can I use these to host in a Windows Service?
CodePudding user response:
You would use the UseWindowsService() extension method documented here:
Implementing this in Startup.cs:
// using nuget package Microsoft.Extensions.Hosting.WindowsServices:
using Microsoft.Extensions.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseWindowsService();
