using Microsoft.Extensions.DependencyInjection; using Avalonia; using System; using AMessanger.ViewModels; using AMessanger.Services; using System.IO; using System.Linq; namespace AMessanger; sealed class Program { public static IServiceProvider Services { get; private set; } = null!; // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] public static void Main(string[] args) { var services = new ServiceCollection(); services.AddSingleton(p => { var url = File .ReadAllLines("ConnectionUrl") .First(l => !string.IsNullOrWhiteSpace(l) && !l.TrimStart().StartsWith('#')); var chat = new ChatService(url); chat.ConnectAsync(); return chat; }); // ViewModels services.AddTransient(); Services = services.BuildServiceProvider(); BuildAvaloniaApp() .StartWithClassicDesktopLifetime(args); } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() #if DEBUG .WithDeveloperTools() #endif .WithInterFont() .LogToTrace(); }