corp-app/CORP-MAUI/ServiceProvider.cs

57 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CORP_MAUI.Services;
namespace CORP_MAUI;
/// <summary>
/// Глобальный провайдер сервисов приложения
/// </summary>
public static class ServiceProvider
{
private static ApiService? _apiService;
private static WebSocketService? _webSocketService;
/// <summary>
/// API-клиент для работы с сервером
/// </summary>
public static ApiService ApiService
{
get
{
_apiService ??= new ApiService();
return _apiService;
}
}
/// <summary>
/// WebSocket-клиент для обмена сообщениями в реальном времени
/// </summary>
public static WebSocketService WebSocketService
{
get
{
_webSocketService ??= new WebSocketService();
return _webSocketService;
}
}
/// <summary>
/// Инициализация всех сервисов
/// </summary>
public static void Initialize()
{
_apiService = new ApiService();
_webSocketService = new WebSocketService();
}
/// <summary>
/// Очистка всех сервисов (при выходе)
/// </summary>
public static void Cleanup()
{
_apiService?.Dispose();
_apiService = null;
_webSocketService = null;
}
}