PathServiceInstaller.cs 1.98 KB
using Microsoft.Extensions.DependencyInjection;
using Rcs.Application.Services;
using Rcs.Application.Services.PathFind;
using Rcs.Application.Services.PathFind.Realtime;
using Rcs.Infrastructure.PathFinding;
using Rcs.Infrastructure.PathFinding.Realtime;
using Rcs.Infrastructure.PathFinding.Services;

namespace Rcs.Infrastructure.Installs;

/// <summary>
/// 路径相关服务注册
/// </summary>
public static class PathInstaller
{
    /// <summary>
    /// 安装HttpClient服务
    /// </summary>
    public static IServiceCollection InstallerPathService(
        this IServiceCollection services)
    {
        // 地图映射服务(按MapCode合并多厂商地图)
        services.AddSingleton<IMapMappingService, MapMappingService>();

        // 统一交通管制服务(基于 MapCode:NodeCode/EdgeCode)
        services.AddSingleton<IUnifiedTrafficControlService, UnifiedTrafficControlService>();

        // 全局实时导航协调器(状态事件驱动)
        services.AddSingleton<IAvoidanceStrategySelector, AvoidanceStrategySelector>();
        services.AddSingleton<IGlobalNavigationCoordinator, GlobalNavigationCoordinator>();
        services.AddHostedService<GlobalNavigationCoordinator>(sp => (GlobalNavigationCoordinator)sp.GetRequiredService<IGlobalNavigationCoordinator>());
        services.AddSingleton<ITailPatchApplier, TailPatchApplier>();
        services.AddSingleton<IGlobalNavigationResumeScheduler, GlobalNavigationResumeScheduler>();
        services.AddHostedService<GlobalNavigationResumeScheduler>(sp => (GlobalNavigationResumeScheduler)sp.GetRequiredService<IGlobalNavigationResumeScheduler>());

        // AGV寻路服务
        services.AddSingleton<IAgvPathService, AgvPathService>();
        services.AddSingleton<AgvPathService>(sp => (AgvPathService)sp.GetRequiredService<IAgvPathService>());

        // 启动时自动初始化合并映射和逆向边关系
        services.AddHostedService<PathServiceInitializer>();

        return services;
    }
}