From 864f6d0f57ed623ed443e0186aff6e4e279e9abd Mon Sep 17 00:00:00 2001 From: Andriy <30056636+West14@users.noreply.github.com> Date: Fri, 21 Jul 2023 18:38:34 +0300 Subject: [PATCH] [core] add IServiceCollection extension for option registration --- Core/Extensions/StartupExtension.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Core/Extensions/StartupExtension.cs b/Core/Extensions/StartupExtension.cs index 1cd4c46..fa40220 100644 --- a/Core/Extensions/StartupExtension.cs +++ b/Core/Extensions/StartupExtension.cs @@ -1,15 +1,20 @@ using System.Collections.Concurrent; using Kruzya.TelegramBot.Core.Cache; +using Kruzya.TelegramBot.Core.Options; using Microsoft.Extensions.DependencyInjection; -namespace Kruzya.TelegramBot.Core.Extensions -{ - public static class StartupExtension - { - public static IServiceCollection AddQueue(this IServiceCollection collection) - => collection.AddSingleton>(); +namespace Kruzya.TelegramBot.Core.Extensions; + +public static class StartupExtension +{ + public static IServiceCollection AddQueue(this IServiceCollection collection) + => collection.AddSingleton>(); + + public static IServiceCollection AddMemoryCache(this IServiceCollection collection) + => collection.AddSingleton>(); + + public static IServiceCollection AddOption(this IServiceCollection collection) where T : class, IOption + => collection.AddScoped() + .AddScoped(s => s.GetService()); - public static IServiceCollection AddMemoryCache(this IServiceCollection collection) - => collection.AddSingleton>(); - } } \ No newline at end of file