mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[core] add IServiceCollection extension for option registration
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using Kruzya.TelegramBot.Core.Cache;
|
using Kruzya.TelegramBot.Core.Cache;
|
||||||
|
using Kruzya.TelegramBot.Core.Options;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
{
|
|
||||||
public static class StartupExtension
|
public static class StartupExtension
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddQueue<T>(this IServiceCollection collection)
|
public static IServiceCollection AddQueue<T>(this IServiceCollection collection)
|
||||||
@@ -11,5 +12,9 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
|
|
||||||
public static IServiceCollection AddMemoryCache<TKey, TValue>(this IServiceCollection collection)
|
public static IServiceCollection AddMemoryCache<TKey, TValue>(this IServiceCollection collection)
|
||||||
=> collection.AddSingleton<MemoryCache<TKey, TValue>>();
|
=> collection.AddSingleton<MemoryCache<TKey, TValue>>();
|
||||||
}
|
|
||||||
|
public static IServiceCollection AddOption<T>(this IServiceCollection collection) where T : class, IOption
|
||||||
|
=> collection.AddScoped<T>()
|
||||||
|
.AddScoped<IOption, T>(s => s.GetService<T>());
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user