How do I get a reference to an IHostedService via Dependency Injection in ASP.NET Core?

后端 未结 3 890
粉色の甜心
粉色の甜心 2021-02-05 11:04

Details

I have attempted to create a background processing structure using the recommended IHostedService interface in ASP.NET 2.1. I register the service

3条回答
  •  萌比男神i
    2021-02-05 11:52

    This is just a slight modification to the answer by @AgentFire. This method is clearer and allows for several background hosted services in a single Web Service.

    services.AddSingleton();
    services.AddHostedService(p => p.GetRequiredService());
    

提交回复
热议问题