Files
better-genshin-impact/BetterGenshinImpact/Service/GearTask/GearTaskServiceExtensions.cs
2025-08-27 02:36:35 +08:00

78 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.Service;
/// <summary>
/// 齿轮任务服务注册扩展方法
/// </summary>
public static class GearTaskServiceExtensions
{
/// <summary>
/// 注册齿轮任务相关服务
/// </summary>
/// <param name="services">服务集合</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddGearTaskServices(this IServiceCollection services)
{
// 注册核心服务
services.AddSingleton<GearTaskStorageService>();
services.AddSingleton<GearTaskFactory>();
services.AddSingleton<GearTaskConverter>();
services.AddTransient<GearTaskExecutionManager>();
services.AddTransient<GearTaskExecutor>();
return services;
}
/// <summary>
/// 注册齿轮任务相关服务(带自定义配置)
/// </summary>
/// <param name="services">服务集合</param>
/// <param name="configureOptions">配置选项</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddGearTaskServices(this IServiceCollection services,
Action<GearTaskServiceOptions>? configureOptions = null)
{
var options = new GearTaskServiceOptions();
configureOptions?.Invoke(options);
// 注册配置
services.AddSingleton(options);
// 注册核心服务
return services.AddGearTaskServices();
}
}
/// <summary>
/// 齿轮任务服务配置选项
/// </summary>
public class GearTaskServiceOptions
{
/// <summary>
/// 是否启用详细日志记录
/// </summary>
public bool EnableVerboseLogging { get; set; } = false;
/// <summary>
/// 任务执行超时时间毫秒0 表示无超时
/// </summary>
public int TaskExecutionTimeoutMs { get; set; } = 0;
/// <summary>
/// 是否在任务失败时继续执行后续任务
/// </summary>
public bool ContinueOnTaskFailure { get; set; } = false;
/// <summary>
/// 最大并发任务数0 表示无限制
/// </summary>
public int MaxConcurrentTasks { get; set; } = 1;
/// <summary>
/// 任务存储路径null 表示使用默认路径
/// </summary>
public string? TaskStoragePath { get; set; }
}