refactoring

This commit is contained in:
Boki 2026-02-13 08:42:46 -05:00
parent 696fd07e86
commit 50d32abd49
20 changed files with 334 additions and 225 deletions

View file

@ -1,8 +1,14 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Poe2Trade.Bot;
using Poe2Trade.Core;
using Poe2Trade.Game;
using Poe2Trade.GameLog;
using Poe2Trade.Inventory;
using Poe2Trade.Screen;
using Poe2Trade.Trade;
using Poe2Trade.Ui.ViewModels;
using Poe2Trade.Ui.Views;
@ -19,15 +25,39 @@ public partial class App : Application
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var store = new ConfigStore();
var config = AppConfig.Load();
var bot = new BotOrchestrator(store, config);
var services = new ServiceCollection();
var mainVm = new MainWindowViewModel(bot)
{
DebugVm = new DebugViewModel(bot),
SettingsVm = new SettingsViewModel(bot)
};
// Config
services.AddSingleton<ConfigStore>();
services.AddSingleton(sp => sp.GetRequiredService<ConfigStore>().Settings);
// Services
services.AddSingleton<IGameController, GameController>();
services.AddSingleton<IScreenReader, ScreenReader>();
services.AddSingleton<IClientLogWatcher>(sp =>
new ClientLogWatcher(sp.GetRequiredService<SavedSettings>().Poe2LogPath));
services.AddSingleton<ITradeMonitor, TradeMonitor>();
services.AddSingleton<IInventoryManager, InventoryManager>();
// Bot
services.AddSingleton<LinkManager>();
services.AddSingleton<TradeExecutor>();
services.AddSingleton<TradeQueue>();
services.AddSingleton<BotOrchestrator>();
// ViewModels
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<DebugViewModel>();
services.AddSingleton<SettingsViewModel>();
var provider = services.BuildServiceProvider();
var store = provider.GetRequiredService<ConfigStore>();
var bot = provider.GetRequiredService<BotOrchestrator>();
var mainVm = provider.GetRequiredService<MainWindowViewModel>();
mainVm.DebugVm = provider.GetRequiredService<DebugViewModel>();
mainVm.SettingsVm = provider.GetRequiredService<SettingsViewModel>();
var window = new MainWindow { DataContext = mainVm };
window.SetConfigStore(store);