Also simplified Generic Host building
This commit is contained in:
@@ -2,14 +2,8 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Polling;
|
||||
using Telegrator.Hosting;
|
||||
using Telegrator.Hosting.Components;
|
||||
using Telegrator.Hosting.Configuration;
|
||||
using Telegrator.Hosting.Providers;
|
||||
using Telegrator.Hosting.Providers.Components;
|
||||
using Telegrator.MadiatorCore;
|
||||
|
||||
#pragma warning disable IDE0001
|
||||
@@ -50,6 +44,7 @@ namespace Telegrator.Hosting
|
||||
_settings = settings ?? new TelegramBotHostBuilderSettings();
|
||||
_handlers = new HostHandlersCollection(Services, _settings);
|
||||
|
||||
_innerBuilder.AddTelegrator(_settings, _handlers);
|
||||
_innerBuilder.Logging.ClearProviders();
|
||||
}
|
||||
|
||||
@@ -65,6 +60,7 @@ namespace Telegrator.Hosting
|
||||
_settings = settings ?? new TelegramBotHostBuilderSettings();
|
||||
_handlers = handlers ?? throw new ArgumentNullException(nameof(handlers));
|
||||
|
||||
_innerBuilder.AddTelegrator(_settings, _handlers);
|
||||
_innerBuilder.Logging.ClearProviders();
|
||||
}
|
||||
|
||||
@@ -74,39 +70,6 @@ namespace Telegrator.Hosting
|
||||
/// <returns></returns>
|
||||
public TelegramBotHost 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<ReceiverOptions>(Configuration.GetSection(nameof(ReceiverOptions)));
|
||||
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy());
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions<ReceiverOptions>)))
|
||||
throw new MissingMemberException("Auto configuration disabled, yet no options of type 'ReceiverOptions' 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<IOptions<TelegratorOptions>>(Options.Create(_settings));
|
||||
Services.AddSingleton<IConfigurationManager>(Configuration);
|
||||
return new TelegramBotHost(_innerBuilder, _handlers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user