* Added missing summaries
This commit is contained in:
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Style", "IDE0290")]
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
||||
|
||||
@@ -49,11 +49,12 @@ namespace Telegrator.Hosting.Web
|
||||
/// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class.
|
||||
/// </summary>
|
||||
/// <param name="webApplicationBuilder">The proxied instance of host builder.</param>
|
||||
/// <param name="handlers"></param>
|
||||
public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder, IHandlersCollection handlers)
|
||||
public TelegramBotWebHost(WebApplicationBuilder webApplicationBuilder)
|
||||
{
|
||||
// Registering this host in services for easy access
|
||||
RegisterHostServices(webApplicationBuilder.Services, handlers);
|
||||
webApplicationBuilder.Services.AddSingleton<ITelegramBotHost>(this);
|
||||
webApplicationBuilder.Services.AddSingleton<ITelegramBotWebHost>(this);
|
||||
webApplicationBuilder.Services.AddSingleton<ITelegratorBot>(this);
|
||||
|
||||
// Building proxy application
|
||||
_innerApp = webApplicationBuilder.Build();
|
||||
@@ -161,15 +162,5 @@ namespace Telegrator.Hosting.Web
|
||||
GC.SuppressFinalize(this);
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
private void RegisterHostServices(IServiceCollection services, IHandlersCollection handlers)
|
||||
{
|
||||
//service.RemoveAll<IHost>();
|
||||
//service.AddSingleton<IHost>(this);
|
||||
|
||||
services.AddSingleton<ITelegramBotHost>(this);
|
||||
services.AddSingleton<ITelegramBotWebHost>(this);
|
||||
services.AddSingleton<ITelegratorBot>(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ namespace Telegrator.Hosting.Web
|
||||
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_handlers = new HostHandlersCollection(Services, _settings);
|
||||
|
||||
_innerBuilder.AddTelegratorWeb(settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,7 +62,7 @@ namespace Telegrator.Hosting.Web
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_handlers = handlers ?? throw new ArgumentNullException(nameof(settings));
|
||||
|
||||
_innerBuilder.AddTelegratorWeb(settings);
|
||||
_innerBuilder.AddTelegratorWeb(settings, handlers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,38 +71,7 @@ namespace Telegrator.Hosting.Web
|
||||
/// <returns></returns>
|
||||
public TelegramBotWebHost Build()
|
||||
{
|
||||
if (_handlers is IHostHandlersCollection hostHandlers)
|
||||
{
|
||||
foreach (PreBuildingRoutine preBuildRoutine in hostHandlers.PreBuilderRoutines)
|
||||
{
|
||||
try
|
||||
{
|
||||
preBuildRoutine.Invoke(this);
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
_ = 0xBAD + 0xC0DE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!_settings.DisableAutoConfigure)
|
||||
{
|
||||
Services.Configure<TelegratorWebOptions>(Configuration.GetSection(nameof(TelegratorWebOptions)));
|
||||
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<TelegratorWebOptions>)))
|
||||
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegratorWebOptions' wasn't registered. This configuration is runtime required!");
|
||||
|
||||
if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<TelegramBotClientOptions>)))
|
||||
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegramBotClientOptions' wasn't registered. This configuration is runtime required!");
|
||||
}
|
||||
|
||||
Services.AddSingleton<IConfigurationManager>(Configuration);
|
||||
Services.AddSingleton<IOptions<TelegratorOptions>>(Options.Create(_settings));
|
||||
return new TelegramBotWebHost(_innerBuilder, _handlers);
|
||||
return new TelegramBotWebHost(_innerBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics;
|
||||
@@ -20,6 +21,19 @@ namespace Telegrator
|
||||
/// </summary>
|
||||
public static class ServicesCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The key used to store the <see cref="IHandlersCollection"/> in the builder properties.
|
||||
/// </summary>
|
||||
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
|
||||
|
||||
extension(IHostApplicationBuilder builder)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IHandlersCollection"/> from the builder properties.
|
||||
/// </summary>
|
||||
public IHandlersCollection Handlers => (IHandlersCollection)builder.Properties[HandlersCollectionPropertyKey];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
/// </summary>
|
||||
@@ -32,6 +46,7 @@ namespace Telegrator
|
||||
ConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
handlers ??= new HostHandlersCollection(services, settings);
|
||||
builder.Host.Properties.Add(HandlersCollectionPropertyKey, handlers);
|
||||
|
||||
if (handlers is IHostHandlersCollection hostHandlers)
|
||||
{
|
||||
@@ -53,6 +68,7 @@ namespace Telegrator
|
||||
if (!settings.DisableAutoConfigure)
|
||||
{
|
||||
services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegratorWebOptions)));
|
||||
services.Configure<TelegratorWebOptions>(configuration.GetSection(nameof(TelegramBotClientOptions)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,8 +108,12 @@ namespace Telegrator
|
||||
ILoggerFactory loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
|
||||
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
|
||||
|
||||
logger.LogInformation("Telegrator Bot ASP.NET WebHost started");
|
||||
logger.LogHandlers(handlers);
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Telegrator Bot ASP.NET WebHost started");
|
||||
logger.LogInformation("Telegram Bot : {firstname}, @{usrname}, id:{id},", info.User.FirstName ?? "[NULL]", info.User.Username ?? "[NULL]", info.User.Id);
|
||||
logger.LogHandlers(handlers);
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user