2025-07-24 23:19:59 +04:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-03-08 19:43:48 +04:00
|
|
|
using Microsoft.Extensions.Diagnostics.Metrics;
|
2025-07-24 23:19:59 +04:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2026-03-06 23:19:24 +04:00
|
|
|
using Telegrator.Core;
|
2025-07-24 23:19:59 +04:00
|
|
|
|
|
|
|
|
#pragma warning disable IDE0001
|
2026-03-09 13:23:21 +04:00
|
|
|
namespace Telegrator.Hosting;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
|
|
|
|
/// </summary>
|
2026-03-15 17:20:53 +04:00
|
|
|
public class TelegramBotHostBuilder : ITelegramBotHostBuilder
|
2025-07-24 23:19:59 +04:00
|
|
|
{
|
2026-03-09 13:23:21 +04:00
|
|
|
private readonly HostApplicationBuilder _innerBuilder;
|
|
|
|
|
private readonly HostApplicationBuilderSettings _settings;
|
|
|
|
|
internal IHandlersCollection _handlers = null!;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IHandlersCollection Handlers => _handlers;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IServiceCollection Services => _innerBuilder.Services;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IConfigurationManager Configuration => _innerBuilder.Configuration;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public ILoggingBuilder Logging => _innerBuilder.Logging;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IHostEnvironment Environment => _innerBuilder.Environment;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IDictionary<object, object> Properties => ((IHostApplicationBuilder)_innerBuilder).Properties;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IMetricsBuilder Metrics => _innerBuilder.Metrics;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TelegramBotHostBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hostApplicationBuilder"></param>
|
|
|
|
|
/// <param name="settings"></param>
|
|
|
|
|
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, HostApplicationBuilderSettings? settings = null)
|
|
|
|
|
{
|
|
|
|
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
|
|
|
|
_settings = settings ?? new HostApplicationBuilderSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TelegramBotHostBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hostApplicationBuilder"></param>
|
|
|
|
|
/// <param name="options"></param>
|
|
|
|
|
/// <param name="settings"></param>
|
|
|
|
|
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, TelegratorOptions? options, HostApplicationBuilderSettings? settings)
|
|
|
|
|
{
|
|
|
|
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
|
|
|
|
_settings = settings ?? new HostApplicationBuilderSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TelegramBotHostBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hostApplicationBuilder"></param>
|
|
|
|
|
/// <param name="handlers"></param>
|
|
|
|
|
/// <param name="settings"></param>
|
|
|
|
|
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers, HostApplicationBuilderSettings? settings)
|
|
|
|
|
{
|
|
|
|
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
|
|
|
|
_settings = settings ?? new HostApplicationBuilderSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-26 00:01:46 +04:00
|
|
|
/// <summary>
|
2026-03-09 13:23:21 +04:00
|
|
|
/// Initializes a new instance of the <see cref="TelegramBotHostBuilder"/> class.
|
2025-07-26 00:01:46 +04:00
|
|
|
/// </summary>
|
2026-03-09 13:23:21 +04:00
|
|
|
/// <param name="hostApplicationBuilder"></param>
|
|
|
|
|
/// <param name="handlers"></param>
|
|
|
|
|
/// <param name="options"></param>
|
|
|
|
|
/// <param name="settings"></param>
|
|
|
|
|
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers, TelegratorOptions? options, HostApplicationBuilderSettings? settings)
|
|
|
|
|
{
|
|
|
|
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
|
|
|
|
_settings = settings ?? new HostApplicationBuilderSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Builds the host.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public TelegramBotHost Build()
|
|
|
|
|
{
|
|
|
|
|
TelegramBotHost host = new TelegramBotHost(_innerBuilder);
|
|
|
|
|
host.UseTelegrator();
|
|
|
|
|
return host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void ConfigureContainer<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull
|
2025-07-24 23:19:59 +04:00
|
|
|
{
|
2026-03-15 17:20:53 +04:00
|
|
|
_innerBuilder.ConfigureContainer(factory, configure);
|
2025-07-24 23:19:59 +04:00
|
|
|
}
|
|
|
|
|
}
|