版本260406
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OrpaonVision.Core.Security;
|
||||
using OrpaonVision.SiteApp.Runtime.Contracts;
|
||||
using OrpaonVision.SiteApp.Runtime.Options;
|
||||
using OrpaonVision.SiteApp.Runtime.Services;
|
||||
using OrpaonVision.SiteApp.ViewModels;
|
||||
using OrpaonVision.ConfigApp.Infrastructure.Services;
|
||||
|
||||
namespace OrpaonVision.SiteApp.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// SiteApp 服务注册扩展。
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册运行端 MVP 相关服务。
|
||||
/// </summary>
|
||||
public static IServiceCollection AddSiteAppServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var runtimeOptions = new RuntimeOptions();
|
||||
configuration.GetSection("Runtime").Bind(runtimeOptions);
|
||||
services.AddSingleton(runtimeOptions);
|
||||
|
||||
// 配置海康相机选项
|
||||
var hikCameraOptions = new HikCameraOptions();
|
||||
configuration.GetSection("HikCamera").Bind(hikCameraOptions);
|
||||
services.AddSingleton(Options.Create(hikCameraOptions));
|
||||
|
||||
// 配置YOLO推理选项
|
||||
var yoloOptions = new YoloInferenceOptions();
|
||||
configuration.GetSection("YoloInference").Bind(yoloOptions);
|
||||
services.AddSingleton(Options.Create(yoloOptions));
|
||||
|
||||
// 注册运行时服务工厂
|
||||
services.AddSingleton<RuntimeServiceFactory>();
|
||||
|
||||
// 注册真实和模拟海康相机服务
|
||||
services.AddSingleton<RealHikCameraService>();
|
||||
services.AddSingleton<MockHikCameraService>();
|
||||
|
||||
// 注册真实和模拟YOLO推理服务
|
||||
services.AddSingleton<RealYoloInferenceService>();
|
||||
services.AddSingleton<MockYoloInferenceService>();
|
||||
|
||||
// 使用工厂模式注册主要服务
|
||||
services.AddSingleton<IHikCameraService>(provider =>
|
||||
provider.GetRequiredService<RuntimeServiceFactory>().CreateHikCameraService());
|
||||
|
||||
services.AddSingleton<IYoloInferenceService>(provider =>
|
||||
provider.GetRequiredService<RuntimeServiceFactory>().CreateYoloInferenceService());
|
||||
|
||||
// 使用海康相机适配器替换Mock实现
|
||||
services.AddSingleton<ICameraService, HikCameraAdapter>();
|
||||
|
||||
// 使用YOLO推理适配器替换Mock实现
|
||||
services.AddSingleton<IInferenceService, YoloInferenceAdapter>();
|
||||
|
||||
services.AddSingleton<IRuleEngineService, AdvancedRuleEngineService>();
|
||||
services.AddSingleton<IRuntimeStateMachineService, AdvancedRuntimeStateMachineService>();
|
||||
services.AddSingleton<MainWindowViewModel>();
|
||||
|
||||
// 机种权限和切换管理服务
|
||||
services.AddSingleton<IProductPermissionService, ProductPermissionService>();
|
||||
services.AddSingleton<IProductSwitchManagerService, ProductSwitchManagerService>();
|
||||
|
||||
// 图像处理服务
|
||||
services.AddSingleton<IImageProcessingService, ImageProcessingService>();
|
||||
services.AddSingleton<OptimizedMainWindowViewModel>();
|
||||
|
||||
// 日志
|
||||
services.AddLogging(builder =>
|
||||
{
|
||||
builder.AddConsole();
|
||||
builder.AddDebug();
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user