| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 3 | | using TeleFlow.Framework.Callbacks; |
| | | 4 | | using TeleFlow.Framework.Dispatching; |
| | | 5 | | using TeleFlow.Framework.RateLimiting; |
| | | 6 | | using TeleFlow.Framework.States; |
| | | 7 | | using TeleFlow.Framework.Updates; |
| | | 8 | | |
| | | 9 | | namespace TeleFlow.Framework.DependencyInjection; |
| | | 10 | | |
| | | 11 | | public static class PolicyServiceCollectionExtensions |
| | | 12 | | { |
| | | 13 | | public static IServiceCollection AddUpdateDispatcher<TDispatcher>(this IServiceCollection services) |
| | | 14 | | where TDispatcher : class, IUpdateDispatcher |
| | | 15 | | { |
| | 2 | 16 | | ArgumentNullException.ThrowIfNull(services); |
| | | 17 | | |
| | 2 | 18 | | services.RemoveAll<IUpdateDispatcher>(); |
| | 2 | 19 | | services.AddSingleton<IUpdateDispatcher, TDispatcher>(); |
| | 2 | 20 | | return services; |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | public static IServiceCollection AddUpdateSource<TSource>(this IServiceCollection services) |
| | | 24 | | where TSource : class, IUpdateSource |
| | | 25 | | { |
| | 5 | 26 | | ArgumentNullException.ThrowIfNull(services); |
| | | 27 | | |
| | 5 | 28 | | services.RemoveAll<IUpdateSource>(); |
| | 5 | 29 | | services.AddSingleton<IUpdateSource, TSource>(); |
| | 5 | 30 | | return services; |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public static IServiceCollection AddCallbackDataSerializer<TSerializer>(this IServiceCollection services) |
| | | 34 | | where TSerializer : class, ICallbackDataSerializer |
| | | 35 | | { |
| | 1 | 36 | | ArgumentNullException.ThrowIfNull(services); |
| | | 37 | | |
| | 1 | 38 | | services.RemoveAll<ICallbackDataSerializer>(); |
| | 1 | 39 | | services.AddSingleton<ICallbackDataSerializer, TSerializer>(); |
| | 1 | 40 | | return services; |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public static IServiceCollection AddStateStore<TStore>(this IServiceCollection services) |
| | | 44 | | where TStore : class, IStateStore |
| | | 45 | | { |
| | 1 | 46 | | ArgumentNullException.ThrowIfNull(services); |
| | | 47 | | |
| | 1 | 48 | | services.RemoveAll<IStateStore>(); |
| | 1 | 49 | | services.AddSingleton<IStateStore, TStore>(); |
| | 1 | 50 | | return services; |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public static IServiceCollection AddStateDataStore<TStore>(this IServiceCollection services) |
| | | 54 | | where TStore : class, IStateDataStore |
| | | 55 | | { |
| | 1 | 56 | | ArgumentNullException.ThrowIfNull(services); |
| | | 57 | | |
| | 1 | 58 | | services.RemoveAll<IStateDataStore>(); |
| | 1 | 59 | | services.AddSingleton<IStateDataStore, TStore>(); |
| | 1 | 60 | | return services; |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | public static IServiceCollection AddStateDataSerializer<TSerializer>(this IServiceCollection services) |
| | | 64 | | where TSerializer : class, IStateDataSerializer |
| | | 65 | | { |
| | 1 | 66 | | ArgumentNullException.ThrowIfNull(services); |
| | | 67 | | |
| | 1 | 68 | | services.RemoveAll<IStateDataSerializer>(); |
| | 1 | 69 | | services.AddSingleton<IStateDataSerializer, TSerializer>(); |
| | 1 | 70 | | return services; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | public static IServiceCollection AddStateHistoryStore<TStore>(this IServiceCollection services) |
| | | 74 | | where TStore : class, IStateHistoryStore |
| | | 75 | | { |
| | 1 | 76 | | ArgumentNullException.ThrowIfNull(services); |
| | | 77 | | |
| | 1 | 78 | | services.RemoveAll<IStateHistoryStore>(); |
| | 1 | 79 | | services.AddSingleton<IStateHistoryStore, TStore>(); |
| | 1 | 80 | | return services; |
| | | 81 | | } |
| | | 82 | | |
| | | 83 | | public static IServiceCollection AddStateKeyFactory<TFactory>(this IServiceCollection services) |
| | | 84 | | where TFactory : class, IStateKeyFactory |
| | | 85 | | { |
| | 1 | 86 | | ArgumentNullException.ThrowIfNull(services); |
| | | 87 | | |
| | 1 | 88 | | services.RemoveAll<IStateKeyFactory>(); |
| | 1 | 89 | | services.AddSingleton<IStateKeyFactory, TFactory>(); |
| | 1 | 90 | | return services; |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | public static IServiceCollection AddStateStorageKeyBuilder<TBuilder>(this IServiceCollection services) |
| | | 94 | | where TBuilder : class, IStateStorageKeyBuilder |
| | | 95 | | { |
| | 1 | 96 | | ArgumentNullException.ThrowIfNull(services); |
| | | 97 | | |
| | 1 | 98 | | services.RemoveAll<IStateStorageKeyBuilder>(); |
| | 1 | 99 | | services.AddSingleton<IStateStorageKeyBuilder, TBuilder>(); |
| | 1 | 100 | | return services; |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | public static IServiceCollection AddUpdateRateLimiter<TLimiter>(this IServiceCollection services) |
| | | 104 | | where TLimiter : class, IUpdateRateLimiter |
| | | 105 | | { |
| | 2 | 106 | | ArgumentNullException.ThrowIfNull(services); |
| | | 107 | | |
| | 2 | 108 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IUpdateRateLimiter, TLimiter>()); |
| | 2 | 109 | | return services; |
| | | 110 | | } |
| | | 111 | | } |