Questionable/Questionable/ServiceCollectionExtensions.cs

45 lines
1.5 KiB
C#
Raw Normal View History

using Dalamud.Plugin.Services;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Questionable.Controller.Steps;
namespace Questionable;
internal static class ServiceCollectionExtensions
{
2024-08-20 00:48:06 +00:00
public static void AddTaskFactory<
[MeansImplicitUse(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
TFactory>(
this IServiceCollection serviceCollection)
where TFactory : class, ITaskFactory
{
serviceCollection.AddSingleton<ITaskFactory, TFactory>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddSingleton<TFactory>();
}
public static void AddTaskExecutor<T,
[MeansImplicitUse(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
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,
[MeansImplicitUse(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
TFactory,
[MeansImplicitUse(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
TExecutor>(
this IServiceCollection serviceCollection)
where TFactory : class, ITaskFactory
where T : class, ITask
where TExecutor : TaskExecutor<T>
{
serviceCollection.AddTaskFactory<TFactory>();
serviceCollection.AddTaskExecutor<T, TExecutor>();
}
}