< Summary

Information
Class: Elsa.Extensions.DependencyInjectionExtensions
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Extensions/DependencyInjectionExtensions.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 57
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
AddMemoryStore(...)100%11100%
AddSerializationOptionsConfigurator(...)100%11100%
AddStartupTask(...)100%11100%
AddBackgroundTask(...)100%11100%
AddRecurringTask(...)100%11100%
AddRecurringTask(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Extensions/DependencyInjectionExtensions.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Common.RecurringTasks;
 3using Elsa.Common.Services;
 4using Microsoft.Extensions.DependencyInjection;
 5using Microsoft.Extensions.DependencyInjection.Extensions;
 6
 7// ReSharper disable once CheckNamespace
 8namespace Elsa.Extensions;
 9
 10/// <summary>
 11/// Extension methods for <see cref="IServiceCollection"/>.
 12/// </summary>
 13public static class DependencyInjectionExtensions
 14{
 15    extension(IServiceCollection services)
 16    {
 17        /// <summary>
 18        /// Adds a memory store for the specified entity.
 19        /// </summary>
 20        public IServiceCollection AddMemoryStore<TEntity, TStore>() where TStore : class
 21        {
 3622            services.TryAddSingleton<MemoryStore<TEntity>>();
 3623            services.TryAddScoped<TStore>();
 3624            return services;
 25        }
 26
 27        /// <summary>
 28        /// Adds a serialization options configurator for the specified type.
 29        /// </summary>
 30        public IServiceCollection AddSerializationOptionsConfigurator<T>() where T : class, ISerializationOptionsConfigu
 31        {
 1832            services.AddSingleton<ISerializationOptionsConfigurator, T>();
 1833            return services;
 34        }
 35
 36        public IServiceCollection AddStartupTask<T>() where T : class, IStartupTask
 37        {
 2738            return services.AddScoped<IStartupTask, T>();
 39        }
 40
 41        public IServiceCollection AddBackgroundTask<T>() where T : class, IBackgroundTask
 42        {
 343            return services.AddScoped<IBackgroundTask, T>();
 44        }
 45
 46        public IServiceCollection AddRecurringTask<T>() where T : class, IRecurringTask
 47        {
 948            return services.AddScoped<IRecurringTask, T>();
 49        }
 50
 51        public IServiceCollection AddRecurringTask<T>(TimeSpan interval) where T : class, IRecurringTask
 52        {
 1853            services.Configure<RecurringTaskOptions>(options => options.Schedule.ConfigureTask<T>(interval));
 954            return services.AddRecurringTask<T>();
 55        }
 56    }
 57}