| | | 1 | | using Elsa.Common; |
| | | 2 | | using Elsa.Common.RecurringTasks; |
| | | 3 | | using Elsa.Common.Services; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 6 | | |
| | | 7 | | // ReSharper disable once CheckNamespace |
| | | 8 | | namespace Elsa.Extensions; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Extension methods for <see cref="IServiceCollection"/>. |
| | | 12 | | /// </summary> |
| | | 13 | | public static class DependencyInjectionExtensions |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Adds a memory store for the specified entity. |
| | | 17 | | /// </summary> |
| | | 18 | | public static IServiceCollection AddMemoryStore<TEntity, TStore>(this IServiceCollection services) where TStore : cl |
| | | 19 | | { |
| | 12 | 20 | | services.TryAddSingleton<MemoryStore<TEntity>>(); |
| | 12 | 21 | | services.TryAddScoped<TStore>(); |
| | 12 | 22 | | return services; |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Adds a serialization options configurator for the specified type. |
| | | 27 | | /// </summary> |
| | | 28 | | public static IServiceCollection AddSerializationOptionsConfigurator<T>(this IServiceCollection services) where T : |
| | | 29 | | { |
| | 6 | 30 | | services.AddSingleton<ISerializationOptionsConfigurator, T>(); |
| | 6 | 31 | | return services; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public static IServiceCollection AddStartupTask<T>(this IServiceCollection services) where T : class, IStartupTask |
| | | 35 | | { |
| | 9 | 36 | | return services.AddScoped<IStartupTask, T>(); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public static IServiceCollection AddBackgroundTask<T>(this IServiceCollection services) where T : class, IBackground |
| | | 40 | | { |
| | 1 | 41 | | return services.AddScoped<IBackgroundTask, T>(); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public static IServiceCollection AddRecurringTask<T>(this IServiceCollection services) where T : class, IRecurringTa |
| | | 45 | | { |
| | 3 | 46 | | return services.AddScoped<IRecurringTask, T>(); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | public static IServiceCollection AddRecurringTask<T>(this IServiceCollection services, TimeSpan interval) where T : |
| | | 50 | | { |
| | 6 | 51 | | services.Configure<RecurringTaskOptions>(options => options.Schedule.ConfigureTask<T>(interval)); |
| | 3 | 52 | | return services.AddRecurringTask<T>(); |
| | | 53 | | } |
| | | 54 | | } |