|
|
|
using CoreAgent.Domain.Contexts;
|
|
|
|
using CoreAgent.Domain.Interfaces;
|
|
|
|
using CoreAgent.Domain.Interfaces.Network;
|
|
|
|
using CoreAgent.Domain.Interfaces.System.Command;
|
|
|
|
using CoreAgent.Infrastructure.Command.Factories;
|
|
|
|
using CoreAgent.Infrastructure.Repositories;
|
|
|
|
using CoreAgent.Infrastructure.Services;
|
|
|
|
using CoreAgent.Infrastructure.Services.Network;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
namespace CoreAgent.Infrastructure.Extensions.ServiceCollection;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 命令服务扩展方法
|
|
|
|
/// </summary>
|
|
|
|
public static class CommandServiceExtensions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 添加命令策略服务
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="services">服务集合</param>
|
|
|
|
/// <returns>服务集合</returns>
|
|
|
|
public static IServiceCollection AddCommandCustomService(this IServiceCollection services)
|
|
|
|
{
|
|
|
|
services.AddSingleton<ICellularNetworkContext, CellularNetworkContext>();
|
|
|
|
// 注册命令执行器工厂
|
|
|
|
services.AddSingleton<ISystemCommandExecutorFactory, SystemCommandExecutorFactory>();
|
|
|
|
|
|
|
|
// 注册命令执行器
|
|
|
|
services.AddTransient<ISystemCommandExecutor>(sp =>
|
|
|
|
{
|
|
|
|
var factory = sp.GetRequiredService<ISystemCommandExecutorFactory>();
|
|
|
|
return factory.CreateExecutor();
|
|
|
|
});
|
|
|
|
// 注册网络配置器
|
|
|
|
services.AddScoped<INetworkConfigurationRepository, NetworkConfigurationRepository>();
|
|
|
|
// 注册网络配置器
|
|
|
|
services.AddScoped<INetworkConfigurationService, NetworkConfigurationService>();
|
|
|
|
|
|
|
|
// 注册网络服务
|
|
|
|
services.AddScoped<ICellularNetworkService, CellularNetworkService>();
|
|
|
|
|
|
|
|
return services;
|
|
|
|
}
|
|
|
|
}
|