1
0

Solution restructured to use multiple test projects

This commit is contained in:
2024-07-04 18:22:26 +02:00
parent 508379d704
commit df6763b99b
144 changed files with 387 additions and 1693 deletions

View File

@@ -0,0 +1,43 @@
using Microsoft.Extensions.Hosting;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extensions for the <see cref="IServiceCollection"/>.
/// </summary>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds a hosted service that is instanciated only once.
/// </summary>
/// <typeparam name="TService">The type of the service to add.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddSingletonHostedService<TService>(this IServiceCollection services)
where TService : class, IHostedService
{
services.AddSingleton<TService>();
services.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<TService>());
return services;
}
/// <summary>
/// Adds a hosted service that is instanciated only once.
/// </summary>
/// <typeparam name="TService">The type of the service to add.</typeparam>
/// <typeparam name="TImplementation">The type of the implementation of the service to add.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddSingletonHostedService<TService, TImplementation>(this IServiceCollection services)
where TService : class, IHostedService
where TImplementation : class, TService
{
services.AddSingleton<TService, TImplementation>();
services.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<TService>());
return services;
}
}
}