1 interface inheriting from IHostedService
Microsoft.Extensions.Hosting.Abstractions (1)
IHostedLifecycleService.cs (1)
14public interface IHostedLifecycleService : IHostedService
20 implementations of IHostedService
Aspire.Hosting (1)
Dashboard\DashboardServiceHost.cs (1)
25internal sealed class DashboardServiceHost : IHostedService
http2cat (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
IIS.FunctionalTests (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
IIS.LongTests (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
IIS.NewHandler.FunctionalTests (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
IIS.NewShim.FunctionalTests (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
IISExpress.FunctionalTests (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
Microsoft.AspNetCore.DataProtection (1)
Internal\DataProtectionHostedService.cs (1)
14internal sealed class DataProtectionHostedService : IHostedService
Microsoft.AspNetCore.Hosting (1)
GenericHost\GenericWebHostService.cs (1)
17internal sealed partial class GenericWebHostService : IHostedService
Microsoft.AspNetCore.Hosting.Tests (5)
WebHostBuilderTests.cs (3)
1423private class MustBeStartedFirst : IHostedService 1526private class ThrowingHostedService : IHostedService 1539private class NonThrowingHostedService : IHostedService
WebHostTests.cs (2)
1145private class TestHostedService : IHostedService, IDisposable 1180private class DelegateHostedService : IHostedService, IDisposable
Microsoft.AspNetCore.Server.HttpSys.FunctionalTests (1)
src\Shared\Http2cat\Http2CatHostedService.cs (1)
24internal sealed class Http2CatHostedService : IHostedService
Microsoft.AspNetCore.Tests (1)
WebApplicationTests.cs (1)
304class HostedService : IHostedService
Microsoft.Extensions.DependencyInjection.AutoActivation (1)
AutoActivationHostedService.cs (1)
13internal sealed class AutoActivationHostedService : IHostedService
Microsoft.Extensions.Diagnostics.HealthChecks (1)
HealthCheckPublisherHostedService.cs (1)
19internal sealed partial class HealthCheckPublisherHostedService : IHostedService
Microsoft.Extensions.Diagnostics.HealthChecks.Tests (1)
DependencyInjection\ServiceCollectionExtensionsTest.cs (1)
83private class DummyHostedService : IHostedService
Microsoft.Extensions.Hosting.Abstractions (1)
BackgroundService.cs (1)
13public abstract class BackgroundService : IHostedService, IDisposable
81 references to IHostedService
Aspire.Hosting (6)
Dashboard\DashboardServiceHost.cs (2)
197async Task IHostedService.StartAsync(CancellationToken cancellationToken) 215async Task IHostedService.StopAsync(CancellationToken cancellationToken)
DistributedApplication.cs (4)
285/// triggered and all <see cref="IHostedService" /> instances are stopped. 303/// of <see cref="IHostedService"/> instances which are added to the dependency injection 316/// <see cref="IHostedService"/> instances are stopped. 332/// of <see cref="IHostedService"/> instances which are added to the dependency injection
Aspire.Hosting.Testing.Tests (1)
ResourceLoggerForwarderServiceTests.cs (1)
24sd.ServiceType == typeof(IHostedService)
Microsoft.AspNetCore (1)
BootstrapHostBuilder.cs (1)
109if (descriptor.ServiceType == typeof(IHostedService))
Microsoft.AspNetCore.DataProtection (1)
DataProtectionServiceCollectionExtensions.cs (1)
77services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, DataProtectionHostedService>());
Microsoft.AspNetCore.Hosting (4)
Internal\HostedServiceExecutor.cs (4)
10private readonly IEnumerable<IHostedService> _services; 12public HostedServiceExecutor(IEnumerable<IHostedService> services) 19foreach (var service in _services) 29foreach (var service in _services)
Microsoft.AspNetCore.Hosting.Tests (10)
WebHostBuilderTests.cs (1)
1378var service = host.Services.GetServices<IHostedService>().OfType<NonThrowingHostedService>().First();
WebHostTests.cs (9)
504services.AddSingleton<IHostedService>(_ => new DelegateHostedService(started, stopping, disposing)); 527services.AddSingleton<IHostedService, TestHostedService>(); 535var svc = (TestHostedService)host.Services.GetRequiredService<IHostedService>(); 558var svc = (TestHostedService)host.Services.GetRequiredService<IHostedService>(); 594services.AddSingleton<IHostedService>(_ => new DelegateHostedService(started, stopping, disposing)); 647services.AddSingleton<IHostedService>(_ => new DelegateHostedService(started, stopping, disposing)); 1070services.AddSingleton<IHostedService, TestHostedService>(); 1075var svc = (TestHostedService)host.Services.GetRequiredService<IHostedService>(); 1125services.AddSingleton<IHostedService>(new DelegateHostedService(started, stopping, () => { }));
Microsoft.AspNetCore.Tests (1)
WebApplicationTests.cs (1)
293builder.Services.AddSingleton<IHostedService>(hostedService);
Microsoft.Extensions.Diagnostics.HealthChecks (1)
DependencyInjection\HealthCheckServiceCollectionExtensions.cs (1)
29services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, HealthCheckPublisherHostedService>());
Microsoft.Extensions.Diagnostics.HealthChecks.Tests (5)
DependencyInjection\ServiceCollectionExtensionsTest.cs (4)
38Assert.Equal(typeof(IHostedService), actual.ServiceType); 52services.AddSingleton<IHostedService, DummyHostedService>(); 68Assert.Equal(typeof(IHostedService), actual.ServiceType); 76Assert.Equal(typeof(IHostedService), actual.ServiceType);
HealthCheckPublisherHostedServiceTest.cs (1)
785return services.GetServices<IHostedService>().OfType<HealthCheckPublisherHostedService>().Single();
Microsoft.Extensions.Diagnostics.Probes (1)
TcpEndpointProbesExtensions.cs (1)
49_ = services.AddSingleton<IHostedService>(provider =>
Microsoft.Extensions.Diagnostics.Probes.Tests (10)
KubernetesProbesExtensionsTests.cs (3)
36var hostedServices = host.Services.GetServices<IHostedService>().Where(service => service.GetType().Name == "TcpEndpointProbesService"); 80var hostedServices = host.Services.GetServices<IHostedService>().Where(service => service.GetType().Name == "TcpEndpointProbesService"); 108var hostedServices = host.Services.GetServices<IHostedService>().Where(service => service.GetType().Name == "TcpEndpointProbesService");
TcpEndpointProbesExtensionsTests.cs (7)
36var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService); 55var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService); 73var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService); 92var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService); 118var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService); 143var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService); 164var hostedServices = host.Services.GetServices<IHostedService>().Where(x => x is TcpEndpointProbesService);
Microsoft.Extensions.Diagnostics.ResourceMonitoring (1)
ResourceMonitorBuilder.cs (1)
20services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, ResourceMonitorService>(static sp => sp.GetRequiredService<ResourceMonitorService>()));
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests (2)
ResourceMonitoringExtensionsTests.cs (2)
80var allHostedServices = provider.GetServices<IHostedService>(); 197var backgrounds = host.Services.GetServices<IHostedService>().Where(x => x is ResourceMonitorService).ToArray();
Microsoft.Extensions.Hosting (12)
HostOptions.cs (4)
37/// Gets or sets a value that indicates if the <see cref="IHost"/> will start registered instances of <see cref="IHostedService"/> concurrently or sequentially. 40/// <see langword="true"/> if the <see cref="IHost"/> will start registered instances of <see cref="IHostedService"/> concurrently; <see langword="false"/> if the <see cref="IHost"/> will start registered instances sequentially. The default is <see langword="false"/> . 45/// Gets or sets a value that indicates if the <see cref="IHost"/> will stop registered instances of <see cref="IHostedService"/> concurrently or sequentially. 48/// <see langword="true"/> if the <see cref="IHost"/> will stop registered instances of <see cref="IHostedService"/> concurrently; <see langword="false"/> if the <see cref="IHost"/> will stop registered instances sequentially. The default is <see langword="false"/> .
Internal\Host.cs (8)
29private IEnumerable<IHostedService>? _hostedServices; 88_hostedServices ??= Services.GetRequiredService<IEnumerable<IHostedService>>(); 244IEnumerable<IHostedService> reversedServices = _hostedServices.Reverse(); 392private static List<IHostedLifecycleService>? GetHostLifecycles(IEnumerable<IHostedService> hostedServices) 396foreach (IHostedService hostedService in hostedServices) 456public List<IHostedService> HostedServices => new List<IHostedService>(host._hostedServices ??= host.Services.GetRequiredService<IEnumerable<IHostedService>>());
Microsoft.Extensions.Hosting.Abstractions (18)
BackgroundService.cs (3)
11/// Base class for implementing a long running <see cref="IHostedService"/>. 27/// This method is called when the <see cref="IHostedService"/> starts. The implementation should return a task that represents 30/// <param name="stoppingToken">Triggered when <see cref="IHostedService.StopAsync(CancellationToken)"/> is called.</param>
IHost.cs (1)
21/// Starts the <see cref="IHostedService" /> objects configured for the program.
IHostedLifecycleService.cs (6)
11/// <see cref="IHostedService.StartAsync(CancellationToken)"/> and 12/// <see cref="IHostedService.StopAsync(CancellationToken)"/>. 17/// Triggered before <see cref="IHostedService.StartAsync(CancellationToken)"/>. 24/// Triggered after <see cref="IHostedService.StartAsync(CancellationToken)"/>. 31/// Triggered before <see cref="IHostedService.StopAsync(CancellationToken)"/>. 38/// Triggered after <see cref="IHostedService.StopAsync(CancellationToken)"/>.
ServiceCollectionHostedServiceExtensions.cs (8)
17/// Add an <see cref="IHostedService"/> registration for the given type. 19/// <typeparam name="THostedService">An <see cref="IHostedService"/> to register.</typeparam> 23where THostedService : class, IHostedService 25services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, THostedService>()); 31/// Add an <see cref="IHostedService"/> registration for the given type. 33/// <typeparam name="THostedService">An <see cref="IHostedService"/> to register.</typeparam> 38where THostedService : class, IHostedService 40services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService>(implementationFactory));
Microsoft.Extensions.Hosting.Testing (2)
FakeHostingExtensions.cs (1)
32public static async Task StartAndStopAsync(this IHostedService service, CancellationToken cancellationToken = default)
HostTerminatorService.cs (1)
40/// <param name="stoppingToken">Triggered when <see cref="IHostedService.StopAsync(CancellationToken)"/> is called.</param>
Microsoft.Extensions.Hosting.Testing.Tests (3)
FakeHostBuilderTests.cs (1)
39Assert.Contains(hostBuilderServices.GetServices<IHostedService>(), x => x is HostTerminatorService);
HostingFakesExtensionsTests.cs (2)
21var exception = await Record.ExceptionAsync(() => ((IHostedService)null!).StartAndStopAsync()); 30var serviceMock = new Mock<IHostedService>(MockBehavior.Strict);
Microsoft.Extensions.Http.Diagnostics.Tests (1)
Logging\HttpClientLoggingExtensionsTest.cs (1)
326.GetRequiredService<IHostedService>()
Nats.Backend (1)
Program.cs (1)
20public class AppEventsBackendService(INatsConnection nats, ILogger<AppEventsBackendService> logger) : IHostedService