using GymLogAI.AI; using GymLogAI.Application.Handlers; using GymLogAI.Persistence; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Telegram.Bot; namespace GymLogAI.TelegramBot; public static class Program { public static async Task Main(string[] args) { var builder = Host.CreateApplicationBuilder(args); builder.Services .AddOptions() .Bind(builder.Configuration.GetSection(TelegramBotOptions.SectionName)); builder.Services.AddPersistence(builder.Configuration); builder.Services.AddAiServices(builder.Configuration); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(serviceProvider => { var options = serviceProvider.GetRequiredService>().Value; return new TelegramBotClient(options.BotToken ?? string.Empty); }); builder.Services.AddScoped(); builder.Services.AddHostedService(); var host = builder.Build(); await using (var scope = host.Services.CreateAsyncScope()) { var dbContext = scope.ServiceProvider.GetRequiredService(); await dbContext.Database.MigrateAsync(); } await host.RunAsync(); } }