Files
SteamTools/System.Application.SteamTools.Client.Desktop.Avalonia/ServiceCollectionExtensions.cs
T
2021-03-08 13:35:02 +08:00

59 lines
2.2 KiB
C#

using Avalonia.Controls;
using System.Application.Services;
using System.Application.Services.Implementation;
using System.Application.UI;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
/// <summary>
/// 添加主线程助手类(MainThreadDesktop)服务
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddMainThreadPlatformService(this IServiceCollection services)
{
services.AddSingleton<IMainThreadPlatformService, MainThreadPlatformServiceImpl>();
return services;
}
/// <summary>
/// 添加弹窗服务
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddMessageWindowService(this IServiceCollection services)
{
services.AddSingleton<IMessageWindowService, MessageWindowServiceImpl>();
return services;
}
/// <summary>
/// 添加应用程序更新服务
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddAppUpdateService(this IServiceCollection services)
{
services.AddSingleton<IAppUpdateService, AvaloniaDesktopAppUpdateServiceImpl>();
return services;
}
/// <summary>
/// 添加托盘图标
/// </summary>
/// <typeparam name="TNotifyIcon"></typeparam>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddNotifyIcon<TNotifyIcon>(this IServiceCollection services) where TNotifyIcon : class, INotifyIcon
{
services.AddSingleton<INotifyIcon<ContextMenu>.IUIFrameworkHelper, INotifyIcon.UIFrameworkHelper>();
services.AddSingleton<TNotifyIcon>();
services.AddSingleton<INotifyIcon>(s => s.GetRequiredService<TNotifyIcon>());
services.AddSingleton<INotifyIcon<ContextMenu>>(s => s.GetRequiredService<TNotifyIcon>());
return services;
}
}
}