为此,必须将 IServicesProvider 或 IServiceScopeFactory 注入托管服务的构造函数中并用于创建范围。 借用文档,服务的构造函数和工作方法可以如下所示: public IServiceProvider Services { get; } public ConsumeScopedServiceHostedService(IServiceProvider services, ILogger<ConsumeScopedServiceHostedService> logger) { ...
(hostedService)) { var genericMethod_AddHostedService = methodInfo.MakeGenericMethod(hostedService); _ = genericMethod_AddHostedService.Invoke(obj: null, parameters: new object[] { services }); // this is like calling services.AddHostedService<T>(), but with dynamic T (= backgroundService)...
In my case I have to be able to access theQueueHostedServicerunning instance and get some report\status. For example currentWorkItemor number of work items in the queue, or number of dequeueed items. I have a service with subscribes on the number of WebSockets on start and I need to ...
在.Net Core2.2和3.1之间的某个地方行为发生了变化,AddHostedService现在添加了一个单例,而不是...