From afb500cfc6a4593013ff4711f73a0ade0ff13941 Mon Sep 17 00:00:00 2001 From: Rikitav Date: Mon, 4 Aug 2025 04:33:34 +0400 Subject: [PATCH] * Added IOptions services checking for host builders --- Telegrator.Hosting.Web/TelegramBotWebHostBuilder.cs | 9 ++++++++- Telegrator.Hosting/TelegramBotHostBuilder.cs | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Telegrator.Hosting.Web/TelegramBotWebHostBuilder.cs b/Telegrator.Hosting.Web/TelegramBotWebHostBuilder.cs index bec7707..058fe97 100644 --- a/Telegrator.Hosting.Web/TelegramBotWebHostBuilder.cs +++ b/Telegrator.Hosting.Web/TelegramBotWebHostBuilder.cs @@ -66,9 +66,16 @@ namespace Telegrator.Hosting.Web if (!_settings.DisableAutoConfigure) { Services.Configure(Configuration.GetSection(nameof(TelegratorWebOptions))); - Services.Configure(Configuration.GetSection(nameof(TelegratorOptions))); Services.Configure(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy()); } + else + { + if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions))) + 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))) + throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegramBotClientOptions' wasn't registered. This configuration is runtime required!"); + } Services.AddSingleton(Configuration); Services.AddSingleton>(Options.Create(_settings)); diff --git a/Telegrator.Hosting/TelegramBotHostBuilder.cs b/Telegrator.Hosting/TelegramBotHostBuilder.cs index 69a0606..955fb50 100644 --- a/Telegrator.Hosting/TelegramBotHostBuilder.cs +++ b/Telegrator.Hosting/TelegramBotHostBuilder.cs @@ -75,6 +75,16 @@ namespace Telegrator.Hosting Services.Configure(Configuration.GetSection(nameof(ReceiverOptions))); Services.Configure(Configuration.GetSection(nameof(TelegramBotClientOptions)), new TelegramBotClientOptionsProxy()); } + else + { + /* + if (null == Services.SingleOrDefault(srvc => srvc.ImplementationType == typeof(IOptions))) + 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))) + throw new MissingMemberException("Auto configuration disabled, yet no options of type 'TelegramBotClientOptions' wasn't registered. This configuration is runtime required!"); + } Services.AddSingleton>(Options.Create(_settings)); Services.AddSingleton(Configuration);