Skip to content

Commit

Permalink
Fixed issues with the BackgroundService with interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simnico99 committed Sep 19, 2022
1 parent 963452b commit 4e1067d
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public static class AddBackgroundServiceExtension
/// <typeparam name="T">The type to add.</typeparam>
/// <param name="services">The service collection.</param>
/// <returns>The service collection.</returns>
public static IServiceCollection AddBackgroundServices<T>(this IServiceCollection services)
where T : BackgroundService
public static IServiceCollection AddBackgroundServices<TImplementation>(this IServiceCollection services)
where TImplementation : BackgroundService
{
services.AddSingleton<T>();
services.AddSingleton<BackgroundService, T>(x => x.GetRequiredService<T>());
services.AddSingleton<IHostedService, T>(x => x.GetRequiredService<T>());
services.AddSingleton<TImplementation>();
services.AddSingleton<BackgroundService, TImplementation>(x => x.GetRequiredService<TImplementation>());
services.AddSingleton<IHostedService, TImplementation>(x => x.GetRequiredService<TImplementation>());

return services;
}
Expand All @@ -29,13 +29,13 @@ public static IServiceCollection AddBackgroundServices<T>(this IServiceCollectio
/// Register the Services with itself, the provided interface, <see cref="IHostedService"/> and <see cref="BackgroundService"/>.
/// </summary>
/// <typeparam name="T">The type to add.</typeparam>
/// <param name="services">The service collection.</param>
/// <returns>The service collection.</returns>
/// <param name="services">The provided <see cref="IServiceCollection"/>.</param>
/// <returns>The provided <see cref="IServiceCollection"/></returns>
public static IServiceCollection AddBackgroundServices<TService, TImplementation>(this IServiceCollection services)
where TService : class
where TImplementation : BackgroundService, TService
{
services.AddSingleton<TService>();
services.AddSingleton<TImplementation>();
services.AddSingleton<TService, TImplementation>(x => x.GetRequiredService<TImplementation>());
services.AddSingleton<BackgroundService, TImplementation>(x => x.GetRequiredService<TImplementation>());
services.AddSingleton<IHostedService, TImplementation>(x => x.GetRequiredService<TImplementation>());
Expand Down

0 comments on commit 4e1067d

Please sign in to comment.