You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using MyAvaloniaApp.Services;
|
|
using MyAvaloniaApp.ViewModels;
|
|
using ReactiveUI;
|
|
using Splat;
|
|
using System;
|
|
|
|
namespace MyAvaloniaApp.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 负责创建
|
|
// 不需要单独注册
|
|
|
|
return services;
|
|
}
|
|
}
|
|
|