using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Telegrator.Hosting.Components;
using Telegrator.Hosting.Providers;
using Telegrator.MadiatorCore;
#pragma warning disable IDE0001
namespace Telegrator.Hosting
{
///
/// Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
///
public class TelegramBotHostBuilder : ITelegramBotHostBuilder
{
private readonly HostApplicationBuilder _innerBuilder;
private readonly TelegramBotHostBuilderSettings _settings;
private readonly IHandlersCollection _handlers;
///
public IHandlersCollection Handlers => _handlers;
///
public IServiceCollection Services => _innerBuilder.Services;
///
public IConfigurationManager Configuration => _innerBuilder.Configuration;
///
public ILoggingBuilder Logging => _innerBuilder.Logging;
///
public IHostEnvironment Environment => _innerBuilder.Environment;
///
/// Initializes a new instance of the class.
///
///
///
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, TelegramBotHostBuilderSettings? settings = null)
{
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
_settings = settings ?? new TelegramBotHostBuilderSettings();
_handlers = new HostHandlersCollection(Services, _settings);
_innerBuilder.AddTelegrator(_settings, _handlers);
_innerBuilder.Logging.ClearProviders();
}
///
/// Initializes a new instance of the class.
///
///
///
///
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers, TelegramBotHostBuilderSettings? settings = null)
{
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
_settings = settings ?? new TelegramBotHostBuilderSettings();
_handlers = handlers ?? throw new ArgumentNullException(nameof(handlers));
_innerBuilder.AddTelegrator(_settings, _handlers);
_innerBuilder.Logging.ClearProviders();
}
///
/// Builds the host.
///
///
public TelegramBotHost Build()
{
return new TelegramBotHost(_innerBuilder, _handlers);
}
}
}