Files
Telegrator/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs
T

74 lines
2.8 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
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
2025-07-24 23:19:59 +04:00
namespace Telegrator.Hosting.Web
{
/// <summary>
/// Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
/// </summary>
public class TelegramBotWebHostBuilder : ITelegramBotHostBuilder
2025-07-24 23:19:59 +04:00
{
private readonly WebApplicationBuilder _innerBuilder;
2026-03-07 02:35:53 +04:00
private readonly WebApplicationOptions _settings;
internal IHandlersCollection _handlers = null!;
2025-07-24 23:19:59 +04:00
/// <inheritdoc/>
public IHandlersCollection Handlers => _handlers;
/// <inheritdoc/>
public IConfigurationManager Configuration => _innerBuilder.Configuration;
/// <inheritdoc/>
public ILoggingBuilder Logging => _innerBuilder.Logging;
/// <inheritdoc/>
public IServiceCollection Services => _innerBuilder.Services;
/// <inheritdoc/>
public IHostEnvironment Environment => _innerBuilder.Environment;
/// <summary>
/// Initializes a new instance of the <see cref="TelegramBotWebHostBuilder"/> class.
/// </summary>
/// <param name="webApplicationBuilder"></param>
/// <param name="settings"></param>
2026-03-07 02:35:53 +04:00
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, WebApplicationOptions settings)
{
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
2026-03-07 00:17:31 +04:00
2026-03-07 20:46:04 +04:00
_innerBuilder.AddTelegratorWeb();
}
/// <summary>
/// Initializes a new instance of the <see cref="TelegramBotWebHostBuilder"/> class.
/// </summary>
/// <param name="webApplicationBuilder"></param>
/// <param name="handlers"></param>
/// <param name="settings"></param>
2026-03-07 02:35:53 +04:00
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, IHandlersCollection handlers, WebApplicationOptions settings)
{
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
2026-03-06 20:49:32 +04:00
2026-03-07 20:46:04 +04:00
_innerBuilder.AddTelegratorWeb(null, handlers);
}
/// <summary>
/// Builds the host.
/// </summary>
/// <returns></returns>
public TelegramBotWebHost Build()
{
2026-03-07 02:35:53 +04:00
TelegramBotWebHost host = new TelegramBotWebHost(_innerBuilder);
host.UseTelegrator();
return host;
}
2025-07-24 23:19:59 +04:00
}
}