using Grpc.Core; using Grpc.Net.Client; using JOBot.Infrastructure.Config; using JOBot.Proto; using JOBot.TClient.Commands.Buttons; using JOBot.TClient.Commands.Commands; using JOBot.TClient.Core.HostedServices; using JOBot.TClient.Queues; using JOBot.TClient.Services; using JOBot.TClient.Statements; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using RabbitMQ.Client; using RabbitMQ.Client.Events; using Telegram.Bot; namespace JOBot.TClient; public static class Startup { public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration config) { services.AddSingleton(config); services.AddScoped(_ => GrpcChannel.ForAddress(config.GetValue("BackendHost") ?? throw new MissingFieldException("Host is not defined"))); #region Commands services.AddScoped(); services.AddScoped(); services.AddScoped(); //buttons services.AddScoped(); #endregion #region gRPC Clients services.AddGrpcClient(o => o.Address = new Uri("http://backend:5001")); #endregion #region Services services.AddSingleton(); services.AddScoped(); services.AddScoped(); #endregion #region States services.AddScoped(); #endregion #region RabbitMQ Clients var factory = new ConnectionFactory { HostName = "localhost" }; using var connection = factory.CreateConnectionAsync().Result; var channel = connection.CreateChannelAsync().Result; channel.QueueDeclareAsync( RabbitQueues.AuthQueue, false, false, false, arguments: null).Wait(); services.AddSingleton(); #endregion // Bot service services.AddHostedService(); services.AddSingleton(_ => new TelegramBotClient(config.GetValue("TelegramToken") ?? throw new MissingFieldException("TelegramToken is not set"))); services.AddLogging(builder => builder.AddConsole()); return services; } }