qstbak/Questionable/Questionable/ServiceCollectionExtensions.cs
2025-10-09 07:47:19 +10:00

25 lines
997 B
C#

using Microsoft.Extensions.DependencyInjection;
using Questionable.Controller.Steps;
namespace Questionable;
internal static class ServiceCollectionExtensions
{
public static void AddTaskFactory<TFactory>(this IServiceCollection serviceCollection) where TFactory : class, ITaskFactory
{
serviceCollection.AddSingleton<ITaskFactory, TFactory>();
serviceCollection.AddSingleton<TFactory>();
}
public static void AddTaskExecutor<T, TExecutor>(this IServiceCollection serviceCollection) where T : class, ITask where TExecutor : TaskExecutor<T>
{
serviceCollection.AddKeyedTransient<ITaskExecutor, TExecutor>(typeof(T));
serviceCollection.AddTransient<TExecutor>();
}
public static void AddTaskFactoryAndExecutor<T, TFactory, TExecutor>(this IServiceCollection serviceCollection) where T : class, ITask where TFactory : class, ITaskFactory where TExecutor : TaskExecutor<T>
{
serviceCollection.AddTaskFactory<TFactory>();
serviceCollection.AddTaskExecutor<T, TExecutor>();
}
}