using Microsoft.Extensions.Hosting; namespace Microsoft.Extensions.DependencyInjection; /// /// Extension method to add session-scoped services to the dependency injection container. /// public static class SessionScopedExtension { /// /// Adds a session-scoped IHostedService service to the services collection. /// /// The type of the hosted service, which must implement . /// The service collection to add the service to. /// The updated service collection. public static IServiceCollection AddSessionScoped(this IServiceCollection services) where T : class, IHostedService { services.AddScoped(); services.AddSingleton>(); services.AddSingleton(provider => provider.GetRequiredService>()); return services; } }