diff --git a/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHost.cs b/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHost.cs
index 3517aa2..f5abd80 100644
--- a/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHost.cs
+++ b/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHost.cs
@@ -7,154 +7,153 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Telegrator.Core;
-namespace Telegrator.Hosting.Web
+namespace Telegrator.Hosting.Web;
+
+///
+/// Represents a web hosted telegram bot
+///
+public class TelegramBotWebHost : IHost, IApplicationBuilder, IEndpointRouteBuilder, IAsyncDisposable
{
+ private readonly WebApplication _innerApp;
+ private readonly IUpdateRouter _updateRouter;
+ private readonly ILogger _logger;
+
+ private bool _disposed;
+
+ ///
+ public IServiceProvider Services => _innerApp.Services;
+
+ ///
+ public IUpdateRouter UpdateRouter => _updateRouter;
+
+ ///
+ public ICollection DataSources => ((IEndpointRouteBuilder)_innerApp).DataSources;
+
///
- /// Represents a web hosted telegram bot
+ /// Allows consumers to be notified of application lifetime events.
///
- public class TelegramBotWebHost : IHost, IApplicationBuilder, IEndpointRouteBuilder, IAsyncDisposable
+ public IHostApplicationLifetime Lifetime => _innerApp.Lifetime;
+
+ ///
+ /// This application's logger
+ ///
+ public ILogger Logger => _logger;
+
+ // Private interface fields
+ IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services;
+ IServiceProvider IApplicationBuilder.ApplicationServices { get => Services; set => throw new NotImplementedException(); }
+ IFeatureCollection IApplicationBuilder.ServerFeatures => ((IApplicationBuilder)_innerApp).ServerFeatures;
+ IDictionary IApplicationBuilder.Properties => ((IApplicationBuilder)_innerApp).Properties;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The proxied instance of host builder.
+ public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder)
{
- private readonly WebApplication _innerApp;
- private readonly IUpdateRouter _updateRouter;
- private readonly ILogger _logger;
+ // Building proxy application
+ _innerApp = webApplicationBuilder.Build();
- private bool _disposed;
+ // Reruesting services for this host
+ _updateRouter = Services.GetRequiredService();
+ _logger = Services.GetRequiredService>();
+ }
- ///
- public IServiceProvider Services => _innerApp.Services;
+ ///
+ /// Creates new with default services and webhook update receiving scheme
+ ///
+ ///
+ public static TelegramBotWebHostBuilder CreateBuilder(WebApplicationOptions settings)
+ {
+ ArgumentNullException.ThrowIfNull(settings, nameof(settings));
+ WebApplicationBuilder innerApp = WebApplication.CreateBuilder(settings);
+ TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
- ///
- public IUpdateRouter UpdateRouter => _updateRouter;
+ builder.Services.AddTelegramBotHostDefaults();
+ builder.Services.AddTelegramWebhook();
+ return builder;
+ }
- ///
- public ICollection DataSources => ((IEndpointRouteBuilder)_innerApp).DataSources;
+ ///
+ /// Creates new SLIM with default services and webhook update receiving scheme
+ ///
+ ///
+ public static TelegramBotWebHostBuilder CreateSlimBuilder(WebApplicationOptions settings)
+ {
+ ArgumentNullException.ThrowIfNull(settings, nameof(settings));
+ WebApplicationBuilder innerApp = WebApplication.CreateSlimBuilder(settings);
+ TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
- ///
- /// Allows consumers to be notified of application lifetime events.
- ///
- public IHostApplicationLifetime Lifetime => _innerApp.Lifetime;
+ builder.Services.AddTelegramBotHostDefaults();
+ builder.Services.AddTelegramWebhook();
+ return builder;
+ }
- ///
- /// This application's logger
- ///
- public ILogger Logger => _logger;
+ ///
+ /// Creates new EMPTY WITHOUT any services or update receiving schemes
+ ///
+ ///
+ public static TelegramBotWebHostBuilder CreateEmptyBuilder(WebApplicationOptions settings)
+ {
+ ArgumentNullException.ThrowIfNull(settings, nameof(settings));
+ WebApplicationBuilder innerApp = WebApplication.CreateEmptyBuilder(settings);
+ return new TelegramBotWebHostBuilder(innerApp, settings);
+ }
- // Private interface fields
- IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services;
- IServiceProvider IApplicationBuilder.ApplicationServices { get => Services; set => throw new NotImplementedException(); }
- IFeatureCollection IApplicationBuilder.ServerFeatures => ((IApplicationBuilder)_innerApp).ServerFeatures;
- IDictionary IApplicationBuilder.Properties => ((IApplicationBuilder)_innerApp).Properties;
+ ///
+ public async Task StartAsync(CancellationToken cancellationToken = default)
+ {
+ await _innerApp.StartAsync(cancellationToken);
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The proxied instance of host builder.
- public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder)
- {
- // Building proxy application
- _innerApp = webApplicationBuilder.Build();
+ ///
+ public async Task StopAsync(CancellationToken cancellationToken = default)
+ {
+ await _innerApp.StopAsync(cancellationToken);
+ }
- // Reruesting services for this host
- _updateRouter = Services.GetRequiredService();
- _logger = Services.GetRequiredService>();
- }
+ ///
+ public IApplicationBuilder CreateApplicationBuilder()
+ => ((IEndpointRouteBuilder)_innerApp).CreateApplicationBuilder();
- ///
- /// Creates new with default services and webhook update receiving scheme
- ///
- ///
- public static TelegramBotWebHostBuilder CreateBuilder(WebApplicationOptions settings)
- {
- ArgumentNullException.ThrowIfNull(settings, nameof(settings));
- WebApplicationBuilder innerApp = WebApplication.CreateBuilder(settings);
- TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
+ ///
+ public IApplicationBuilder Use(Func middleware)
+ => _innerApp.Use(middleware);
- builder.Services.AddTelegramBotHostDefaults();
- builder.Services.AddTelegramWebhook();
- return builder;
- }
+ ///
+ public IApplicationBuilder New()
+ => ((IApplicationBuilder)_innerApp).New();
- ///
- /// Creates new SLIM with default services and webhook update receiving scheme
- ///
- ///
- public static TelegramBotWebHostBuilder CreateSlimBuilder(WebApplicationOptions settings)
- {
- ArgumentNullException.ThrowIfNull(settings, nameof(settings));
- WebApplicationBuilder innerApp = WebApplication.CreateSlimBuilder(settings);
- TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
+ ///
+ public RequestDelegate Build()
+ => ((IApplicationBuilder)_innerApp).Build();
- builder.Services.AddTelegramBotHostDefaults();
- builder.Services.AddTelegramWebhook();
- return builder;
- }
+ ///
+ /// Disposes the host.
+ ///
+ public async ValueTask DisposeAsync()
+ {
+ if (_disposed)
+ return;
- ///
- /// Creates new EMPTY WITHOUT any services or update receiving schemes
- ///
- ///
- public static TelegramBotWebHostBuilder CreateEmptyBuilder(WebApplicationOptions settings)
- {
- ArgumentNullException.ThrowIfNull(settings, nameof(settings));
- WebApplicationBuilder innerApp = WebApplication.CreateEmptyBuilder(settings);
- return new TelegramBotWebHostBuilder(innerApp, settings);
- }
+ await _innerApp.DisposeAsync();
- ///
- public async Task StartAsync(CancellationToken cancellationToken = default)
- {
- await _innerApp.StartAsync(cancellationToken);
- }
+ GC.SuppressFinalize(this);
+ _disposed = true;
+ }
- ///
- public async Task StopAsync(CancellationToken cancellationToken = default)
- {
- await _innerApp.StopAsync(cancellationToken);
- }
+ ///
+ /// Disposes the host.
+ ///
+ public void Dispose()
+ {
+ if (_disposed)
+ return;
- ///
- public IApplicationBuilder CreateApplicationBuilder()
- => ((IEndpointRouteBuilder)_innerApp).CreateApplicationBuilder();
+ ValueTask disposeTask = _innerApp.DisposeAsync();
+ disposeTask.AsTask().Wait();
- ///
- public IApplicationBuilder Use(Func middleware)
- => _innerApp.Use(middleware);
-
- ///
- public IApplicationBuilder New()
- => ((IApplicationBuilder)_innerApp).New();
-
- ///
- public RequestDelegate Build()
- => ((IApplicationBuilder)_innerApp).Build();
-
- ///
- /// Disposes the host.
- ///
- public async ValueTask DisposeAsync()
- {
- if (_disposed)
- return;
-
- await _innerApp.DisposeAsync();
-
- GC.SuppressFinalize(this);
- _disposed = true;
- }
-
- ///
- /// Disposes the host.
- ///
- public void Dispose()
- {
- if (_disposed)
- return;
-
- ValueTask disposeTask = _innerApp.DisposeAsync();
- disposeTask.AsTask().Wait();
-
- GC.SuppressFinalize(this);
- _disposed = true;
- }
+ GC.SuppressFinalize(this);
+ _disposed = true;
}
}
diff --git a/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs b/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs
index 16f8de7..c561bcd 100644
--- a/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs
+++ b/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs
@@ -7,109 +7,108 @@ using Microsoft.Extensions.Logging;
using Telegrator.Core;
#pragma warning disable IDE0001
-namespace Telegrator.Hosting.Web
+namespace Telegrator.Hosting.Web;
+
+///
+/// Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
+///
+public class TelegramBotWebHostBuilder : IHostApplicationBuilder, ICollectingProvider
{
+ private readonly WebApplicationBuilder _innerBuilder;
+ private readonly WebApplicationOptions _settings;
+ internal IHandlersCollection _handlers = null!;
+
+ ///
+ public IHandlersCollection Handlers => _handlers;
+
+ ///
+ public IConfigurationManager Configuration => _innerBuilder.Configuration;
+
+ ///
+ public ILoggingBuilder Logging => _innerBuilder.Logging;
+
+ ///
+ public IServiceCollection Services => _innerBuilder.Services;
+
+ ///
+ public IHostEnvironment Environment => _innerBuilder.Environment;
+
+ ///
+ public IDictionary