|
|
|
|
using AuroraDesk.Core.Interfaces;
|
|
|
|
|
using AuroraDesk.Presentation.ViewModels;
|
|
|
|
|
using AuroraDesk.Presentation.ViewModels.Pages;
|
|
|
|
|
using AuroraDesk.Presentation.Services;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
namespace AuroraDesk.Presentation.Extensions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务集合扩展方法(表示层)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加 ReactiveUI 相关服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services">服务集合</param>
|
|
|
|
|
/// <returns>服务集合</returns>
|
|
|
|
|
public static IServiceCollection AddReactiveUI(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// 注册 ReactiveUI 相关服务
|
|
|
|
|
services.AddSingleton<AppViewModel>();
|
|
|
|
|
services.AddSingleton<IScreen>(provider => provider.GetRequiredService<AppViewModel>());
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加 ViewModel 服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services">服务集合</param>
|
|
|
|
|
/// <returns>服务集合</returns>
|
|
|
|
|
public static IServiceCollection AddViewModels(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// 注册 PageViewModelFactory(实现 Core 层接口)
|
|
|
|
|
services.AddTransient<IPageViewModelFactory, PageViewModelFactory>();
|
|
|
|
|
|
|
|
|
|
// 注册所有 PageViewModel 为 Transient
|
|
|
|
|
services.AddTransient<DashboardPageViewModel>();
|
|
|
|
|
services.AddTransient<UsersPageViewModel>();
|
|
|
|
|
services.AddTransient<SettingsPageViewModel>();
|
|
|
|
|
services.AddTransient<ReportsPageViewModel>();
|
|
|
|
|
services.AddTransient<HelpPageViewModel>();
|
|
|
|
|
services.AddTransient<DialogHostPageViewModel>();
|
|
|
|
|
services.AddTransient<IconsPageViewModel>();
|
|
|
|
|
services.AddTransient<EditorPageViewModel>();
|
|
|
|
|
services.AddTransient<UdpClientPageViewModel>();
|
|
|
|
|
services.AddTransient<UdpServerPageViewModel>();
|
|
|
|
|
services.AddTransient<NodeCanvasPageViewModel>();
|
|
|
|
|
services.AddTransient<PlinkPageViewModel>();
|
|
|
|
|
services.AddTransient<SshPageViewModel>();
|
|
|
|
|
|
|
|
|
|
// 注意:MainWindowViewModel 的注册移到主项目的 App.axaml.cs 中
|
|
|
|
|
// 因为它依赖 AppViewModel,而 AppViewModel 在 AddReactiveUI() 中注册
|
|
|
|
|
// 必须在 AddReactiveUI() 之后注册 MainWindowViewModel
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|