|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using AuroraDesk.Services;
|
|
|
|
|
using AuroraDesk.ViewModels;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using Splat;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace AuroraDesk.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>
|
|
|
|
|
/// 娣诲姞涓氬姟鏈嶅姟
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services">鏈嶅姟闆嗗悎</param>
|
|
|
|
|
/// <returns>鏈嶅姟闆嗗悎</returns>
|
|
|
|
|
public static IServiceCollection AddBusinessServices(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// 娉ㄥ唽涓氬姟鏈嶅姟
|
|
|
|
|
services.AddTransient<IDataService, DataService>();
|
|
|
|
|
services.AddTransient<IApiService, ApiService>();
|
|
|
|
|
|
|
|
|
|
// 娉ㄥ唽璧勬簮鏈嶅姟
|
|
|
|
|
services.AddSingleton<IResourceService, ResourceService>();
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 娣诲姞 ViewModel 鏈嶅姟
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services">鏈嶅姟闆嗗悎</param>
|
|
|
|
|
/// <returns>鏈嶅姟闆嗗悎</returns>
|
|
|
|
|
public static IServiceCollection AddViewModels(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// 娉ㄥ唽 MainWindowViewModel锛岄€氳繃 AppViewModel 鑾峰彇
|
|
|
|
|
// 娉ㄦ剰锛氶渶瑕佸厛娉ㄥ唽 AppViewModel
|
|
|
|
|
services.AddTransient<MainWindowViewModel>(provider =>
|
|
|
|
|
{
|
|
|
|
|
var appViewModel = provider.GetRequiredService<AppViewModel>();
|
|
|
|
|
return appViewModel.MainWindowViewModel;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|