This commit is contained in:
Lightczx 2024-03-28 14:00:29 +08:00
parent fdd48f4f62
commit 1c97b425f4
12 changed files with 49 additions and 27 deletions

View File

@ -1,5 +1,6 @@
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Service;
using BetterGenshinImpact.Service.Interface;
using BetterGenshinImpact.View;
@ -67,26 +68,17 @@ public partial class App : Application
services.AddSingleton<INavigationService, NavigationService>();
// Main window with navigation
services.AddSingleton<INavigationWindow, MainWindow>();
services.AddSingleton<MainWindowViewModel>();
services.AddView<INavigationWindow, MainWindow, MainWindowViewModel>();
services.AddSingleton<NotifyIconViewModel>();
// Views and ViewModels
services.AddSingleton<HomePage>();
services.AddSingleton<HomePageViewModel>();
services.AddSingleton<ScriptControlPage>();
services.AddSingleton<ScriptControlViewModel>();
services.AddSingleton<TriggerSettingsPage>();
services.AddSingleton<TriggerSettingsPageViewModel>();
services.AddSingleton<MacroSettingsPage>();
services.AddSingleton<MacroSettingsPageViewModel>();
services.AddSingleton<CommonSettingsPage>();
services.AddSingleton<CommonSettingsPageViewModel>();
services.AddSingleton<TaskSettingsPage>();
services.AddSingleton<TaskSettingsPageViewModel>();
services.AddSingleton<HotKeyPage>();
services.AddSingleton<HotKeyPageViewModel>();
// Views
services.AddView<HomePage, HomePageViewModel>();
services.AddView<ScriptControlPage, ScriptControlViewModel>();
services.AddView<TriggerSettingsPage, TriggerSettingsPageViewModel>();
services.AddView<MacroSettingsPage, MacroSettingsPageViewModel>();
services.AddView<CommonSettingsPage, CommonSettingsPageViewModel>();
services.AddView<TaskSettingsPage, TaskSettingsPageViewModel>();
services.AddView<HotKeyPage, HotKeyPageViewModel>();
// My Services
services.AddSingleton<TaskTriggerDispatcher>();

View File

@ -0,0 +1,27 @@
using BetterGenshinImpact.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using System.Windows.Controls;
namespace BetterGenshinImpact.Helpers.Extensions;
internal static class DependencyInjectionExtensions
{
public static IServiceCollection AddView<TWindow, TWindowImplementation, TViewModel>(this IServiceCollection services)
where TWindow : class
where TWindowImplementation : class, TWindow
where TViewModel : class, IViewModel
{
return services
.AddSingleton<TWindow, TWindowImplementation>()
.AddSingleton<TViewModel>();
}
public static IServiceCollection AddView<TPage, TViewModel>(this IServiceCollection services)
where TPage : Page
where TViewModel : class, IViewModel
{
return services
.AddSingleton<TPage>()
.AddSingleton<TViewModel>();
}
}

View File

@ -0,0 +1,3 @@
namespace BetterGenshinImpact.ViewModel;
internal interface IViewModel;

View File

@ -19,7 +19,7 @@ using Wpf.Ui;
namespace BetterGenshinImpact.ViewModel;
public partial class MainWindowViewModel : ObservableObject
public partial class MainWindowViewModel : ObservableObject, IViewModel
{
private readonly ILogger<MainWindowViewModel> _logger;
private readonly IConfigService _configService;

View File

@ -60,4 +60,4 @@ file static class WindowBacktray
}
}
}
}
}

View File

@ -16,7 +16,7 @@ using BetterGenshinImpact.View.Windows;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class CommonSettingsPageViewModel : ObservableObject, INavigationAware
public partial class CommonSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }

View File

@ -20,7 +20,7 @@ using Wpf.Ui.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class HomePageViewModel : ObservableObject, INavigationAware
public partial class HomePageViewModel : ObservableObject, INavigationAware, IViewModel
{
[ObservableProperty] private string[] _modeNames = GameCaptureFactory.ModeNames();

View File

@ -17,7 +17,7 @@ using BetterGenshinImpact.Model;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class HotKeyPageViewModel : ObservableObject
public partial class HotKeyPageViewModel : ObservableObject, IViewModel
{
private readonly ILogger<HotKeyPageViewModel> _logger;
private readonly TaskSettingsPageViewModel _taskSettingsPageViewModel;

View File

@ -9,7 +9,7 @@ using Wpf.Ui.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class MacroSettingsPageViewModel : ObservableObject, INavigationAware
public partial class MacroSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }

View File

@ -9,7 +9,7 @@ using System.Diagnostics;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class ScriptControlViewModel : ObservableObject, INavigationAware
public partial class ScriptControlViewModel : ObservableObject, INavigationAware, IViewModel
{
public ScriptControlViewModel()
{

View File

@ -18,7 +18,7 @@ using MessageBox = System.Windows.MessageBox;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAware
public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }

View File

@ -11,7 +11,7 @@ using Wpf.Ui.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class TriggerSettingsPageViewModel : ObservableObject, INavigationAware
public partial class TriggerSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }