< Summary

Information
Class: TeleFlow.Framework.DependencyInjection.PolicyServiceCollectionExtensions
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/DependencyInjection/PolicyServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 111
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddUpdateDispatcher(...)100%11100%
AddUpdateSource(...)100%11100%
AddCallbackDataSerializer(...)100%11100%
AddStateStore(...)100%11100%
AddStateDataStore(...)100%11100%
AddStateDataSerializer(...)100%11100%
AddStateHistoryStore(...)100%11100%
AddStateKeyFactory(...)100%11100%
AddStateStorageKeyBuilder(...)100%11100%
AddUpdateRateLimiter(...)100%11100%

File(s)

/_/src/TeleFlow.Framework.Core/DependencyInjection/PolicyServiceCollectionExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.DependencyInjection.Extensions;
 3using TeleFlow.Framework.Callbacks;
 4using TeleFlow.Framework.Dispatching;
 5using TeleFlow.Framework.RateLimiting;
 6using TeleFlow.Framework.States;
 7using TeleFlow.Framework.Updates;
 8
 9namespace TeleFlow.Framework.DependencyInjection;
 10
 11public static class PolicyServiceCollectionExtensions
 12{
 13    public static IServiceCollection AddUpdateDispatcher<TDispatcher>(this IServiceCollection services)
 14        where TDispatcher : class, IUpdateDispatcher
 15    {
 216        ArgumentNullException.ThrowIfNull(services);
 17
 218        services.RemoveAll<IUpdateDispatcher>();
 219        services.AddSingleton<IUpdateDispatcher, TDispatcher>();
 220        return services;
 21    }
 22
 23    public static IServiceCollection AddUpdateSource<TSource>(this IServiceCollection services)
 24        where TSource : class, IUpdateSource
 25    {
 526        ArgumentNullException.ThrowIfNull(services);
 27
 528        services.RemoveAll<IUpdateSource>();
 529        services.AddSingleton<IUpdateSource, TSource>();
 530        return services;
 31    }
 32
 33    public static IServiceCollection AddCallbackDataSerializer<TSerializer>(this IServiceCollection services)
 34        where TSerializer : class, ICallbackDataSerializer
 35    {
 136        ArgumentNullException.ThrowIfNull(services);
 37
 138        services.RemoveAll<ICallbackDataSerializer>();
 139        services.AddSingleton<ICallbackDataSerializer, TSerializer>();
 140        return services;
 41    }
 42
 43    public static IServiceCollection AddStateStore<TStore>(this IServiceCollection services)
 44        where TStore : class, IStateStore
 45    {
 146        ArgumentNullException.ThrowIfNull(services);
 47
 148        services.RemoveAll<IStateStore>();
 149        services.AddSingleton<IStateStore, TStore>();
 150        return services;
 51    }
 52
 53    public static IServiceCollection AddStateDataStore<TStore>(this IServiceCollection services)
 54        where TStore : class, IStateDataStore
 55    {
 156        ArgumentNullException.ThrowIfNull(services);
 57
 158        services.RemoveAll<IStateDataStore>();
 159        services.AddSingleton<IStateDataStore, TStore>();
 160        return services;
 61    }
 62
 63    public static IServiceCollection AddStateDataSerializer<TSerializer>(this IServiceCollection services)
 64        where TSerializer : class, IStateDataSerializer
 65    {
 166        ArgumentNullException.ThrowIfNull(services);
 67
 168        services.RemoveAll<IStateDataSerializer>();
 169        services.AddSingleton<IStateDataSerializer, TSerializer>();
 170        return services;
 71    }
 72
 73    public static IServiceCollection AddStateHistoryStore<TStore>(this IServiceCollection services)
 74        where TStore : class, IStateHistoryStore
 75    {
 176        ArgumentNullException.ThrowIfNull(services);
 77
 178        services.RemoveAll<IStateHistoryStore>();
 179        services.AddSingleton<IStateHistoryStore, TStore>();
 180        return services;
 81    }
 82
 83    public static IServiceCollection AddStateKeyFactory<TFactory>(this IServiceCollection services)
 84        where TFactory : class, IStateKeyFactory
 85    {
 186        ArgumentNullException.ThrowIfNull(services);
 87
 188        services.RemoveAll<IStateKeyFactory>();
 189        services.AddSingleton<IStateKeyFactory, TFactory>();
 190        return services;
 91    }
 92
 93    public static IServiceCollection AddStateStorageKeyBuilder<TBuilder>(this IServiceCollection services)
 94        where TBuilder : class, IStateStorageKeyBuilder
 95    {
 196        ArgumentNullException.ThrowIfNull(services);
 97
 198        services.RemoveAll<IStateStorageKeyBuilder>();
 199        services.AddSingleton<IStateStorageKeyBuilder, TBuilder>();
 1100        return services;
 101    }
 102
 103    public static IServiceCollection AddUpdateRateLimiter<TLimiter>(this IServiceCollection services)
 104        where TLimiter : class, IUpdateRateLimiter
 105    {
 2106        ArgumentNullException.ThrowIfNull(services);
 107
 2108        services.TryAddEnumerable(ServiceDescriptor.Singleton<IUpdateRateLimiter, TLimiter>());
 2109        return services;
 110    }
 111}