using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.Service; /// /// 齿轮任务服务注册扩展方法 /// public static class GearTaskServiceExtensions { /// /// 注册齿轮任务相关服务 /// /// 服务集合 /// 服务集合 public static IServiceCollection AddGearTaskServices(this IServiceCollection services) { // 注册核心服务 services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); return services; } /// /// 注册齿轮任务相关服务(带自定义配置) /// /// 服务集合 /// 配置选项 /// 服务集合 public static IServiceCollection AddGearTaskServices(this IServiceCollection services, Action? configureOptions = null) { var options = new GearTaskServiceOptions(); configureOptions?.Invoke(options); // 注册配置 services.AddSingleton(options); // 注册核心服务 return services.AddGearTaskServices(); } } /// /// 齿轮任务服务配置选项 /// public class GearTaskServiceOptions { /// /// 是否启用详细日志记录 /// public bool EnableVerboseLogging { get; set; } = false; /// /// 任务执行超时时间(毫秒),0 表示无超时 /// public int TaskExecutionTimeoutMs { get; set; } = 0; /// /// 是否在任务失败时继续执行后续任务 /// public bool ContinueOnTaskFailure { get; set; } = false; /// /// 最大并发任务数,0 表示无限制 /// public int MaxConcurrentTasks { get; set; } = 1; /// /// 任务存储路径,null 表示使用默认路径 /// public string? TaskStoragePath { get; set; } }