* Added IOptions services checking for host builders

This commit is contained in:
2025-08-04 04:33:34 +04:00
parent cb9e158e6c
commit afb500cfc6
2 changed files with 18 additions and 1 deletions
@@ -66,9 +66,16 @@ namespace Telegrator.Hosting.Web
if (!_settings.DisableAutoConfigure) if (!_settings.DisableAutoConfigure)
{ {
Services.Configure<TelegratorWebOptions>(Configuration.GetSection(nameof(TelegratorWebOptions))); Services.Configure<TelegratorWebOptions>(Configuration.GetSection(nameof(TelegratorWebOptions)));
Services.Configure<TelegratorOptions>(Configuration.GetSection(nameof(TelegratorOptions)));
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy()); 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<IConfigurationManager>(Configuration);
Services.AddSingleton<IOptions<TelegratorOptions>>(Options.Create(_settings)); Services.AddSingleton<IOptions<TelegratorOptions>>(Options.Create(_settings));
@@ -75,6 +75,16 @@ namespace Telegrator.Hosting
Services.Configure<ReceiverOptions>(Configuration.GetSection(nameof(ReceiverOptions))); Services.Configure<ReceiverOptions>(Configuration.GetSection(nameof(ReceiverOptions)));
Services.Configure<TelegramBotClientOptions>(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy()); 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<IOptions<TelegratorOptions>>(Options.Create(_settings));
Services.AddSingleton<IConfigurationManager>(Configuration); Services.AddSingleton<IConfigurationManager>(Configuration);