Files
telegram-bot/Core/Extensions/StartupExtension.cs
T

20 lines
793 B
C#
Raw Normal View History

2020-03-02 00:00:44 +04:00
using System.Collections.Concurrent;
2020-03-03 14:11:51 +04:00
using Kruzya.TelegramBot.Core.Cache;
using Kruzya.TelegramBot.Core.Options;
2020-03-02 00:00:44 +04:00
using Microsoft.Extensions.DependencyInjection;
namespace Kruzya.TelegramBot.Core.Extensions;
public static class StartupExtension
2020-03-02 00:00:44 +04:00
{
public static IServiceCollection AddQueue<T>(this IServiceCollection collection)
=> collection.AddSingleton<ConcurrentQueue<T>>();
public static IServiceCollection AddMemoryCache<TKey, TValue>(this IServiceCollection collection)
=> 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>());
2020-03-02 00:00:44 +04:00
}