big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-11-17 13:14:05 +02:00
parent 22529c26ec
commit e7ea5a8ded
38 changed files with 808 additions and 157 deletions
+25 -7
View File
@@ -13,6 +13,7 @@ using Azaion.Common.Extensions;
using Azaion.Common.Services;
using Azaion.Common.Services.Inference;
using Azaion.Dataset;
using Azaion.Suite.Services;
using CommandLine;
using LibVLCSharp.Shared;
using MediatR;
@@ -98,8 +99,9 @@ public partial class App
new ConfigUpdater().CheckConfig();
var initConfig = Constants.ReadInitConfig(Log.Logger);
var apiDir = initConfig.DirectoriesConfig.ApiResourcesDirectory;
var processLauncher = new ProcessLauncher();
_loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, _mainCTokenSource.Token);
_loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, processLauncher, _mainCTokenSource.Token);
_loaderClient.StartClient();
_loaderClient.Connect();
_loaderClient.Login(credentials);
@@ -145,7 +147,16 @@ public partial class App
services.AddSingleton<IAzaionApi>(azaionApi);
#endregion
services.AddSingleton<IFileSystem, PhysicalFileSystem>();
services.AddSingleton<IConfigurationStore>(sp =>
new FileConfigurationStore(Constants.CONFIG_PATH, sp.GetRequiredService<IFileSystem>()));
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
services.AddSingleton<IProcessLauncher, ProcessLauncher>();
services.AddSingleton<IUICommandDispatcher>(_ =>
new WpfUICommandDispatcher(Application.Current.Dispatcher));
services.AddSingleton<IAnnotationPathResolver>(sp =>
new AnnotationPathResolver(sp.GetRequiredService<IOptions<Azaion.Common.DTO.DirectoriesConfig>>().Value));
services.AddSingleton<IDetectionClassProvider, DetectionClassProvider>();
services.AddSingleton<Annotator.Annotator>();
services.AddSingleton<DatasetExplorer>();
services.AddSingleton<HelpWindow>();
@@ -155,16 +166,18 @@ public partial class App
typeof(AnnotationService).Assembly));
services.AddSingleton<LibVLC>(_ => new LibVLC("--no-osd", "--no-video-title-show", "--no-snapshot-preview"));
services.AddSingleton<FormState>();
services.AddSingleton<MediaPlayer>(sp =>
services.AddSingleton<LibVLCSharp.Shared.MediaPlayer>(sp =>
{
var libVlc = sp.GetRequiredService<LibVLC>();
return new MediaPlayer(libVlc);
return new LibVLCSharp.Shared.MediaPlayer(libVlc);
});
services.AddSingleton<IMediaPlayerService>(sp =>
new VlcMediaPlayerService(sp.GetRequiredService<LibVLCSharp.Shared.MediaPlayer>(), sp.GetRequiredService<LibVLC>()));
services.AddSingleton<AnnotatorEventHandler>();
services.AddSingleton<IDbFactory, DbFactory>();
services.AddSingleton<FailsafeAnnotationsProducer>();
services.AddSingleton<IAnnotationRepository, AnnotationRepository>();
services.AddSingleton<IAnnotationService, AnnotationService>();
services.AddSingleton<DatasetExplorer>();
@@ -175,9 +188,6 @@ public partial class App
})
.Build();
Annotation.Init(_host.Services.GetRequiredService<IOptions<DirectoriesConfig>>().Value,
_host.Services.GetRequiredService<IOptions<AnnotationConfig>>().Value.DetectionClassesDict);
_host.Services.GetRequiredService<DatasetExplorer>();
_mediator = _host.Services.GetRequiredService<IMediator>();
@@ -186,6 +196,14 @@ public partial class App
DispatcherUnhandledException += OnDispatcherUnhandledException;
_host.Start();
_ = Task.Run(async () =>
{
await _host.Services.GetRequiredService<IAnnotationService>().StartQueueConsumerAsync();
await _host.Services.GetRequiredService<FailsafeAnnotationsProducer>().StartAsync();
await _host.Services.GetRequiredService<IInferenceService>().StartAsync();
});
EventManager.RegisterClassHandler(typeof(UIElement), UIElement.PreviewKeyDownEvent, new RoutedEventHandler(GlobalKeyHandler));
_host.Services.GetRequiredService<MainSuite>().Show();
}