Add a Worker Service to Web API Project

Startup.cs

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public void ConfigureServices(IServiceCollection services)
{
services.AddHostedService<Worker>(); // the worker will run
services.AddControllers();
}
public void ConfigureServices(IServiceCollection services) { services.AddHostedService<Worker>(); // the worker will run services.AddControllers(); }
public void ConfigureServices(IServiceCollection services)
{
    services.AddHostedService<Worker>();  // the worker will run
    services.AddControllers();
}

References
https://stackoverflow.com/questions/58274763/hosting-web-api-in-net-core-worker-service-cannot-reference-iwebhostenvironme