using Microsoft.Extensions.Hosting; namespace Microsoft.Extensions.DependencyInjection { /// /// Extensions for the . /// public static class ServiceCollectionExtensions { /// /// Adds a hosted service that is instanciated only once. /// /// The type of the service to add. /// The to add the service to. /// A reference to this instance after the operation has completed. public static IServiceCollection AddSingletonHostedService(this IServiceCollection services) where TService : class, IHostedService { services.AddSingleton(); services.AddSingleton>(); return services; } } }