| | | 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 | | 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 | | { |
| | 36 | 22 | | services.TryAddSingleton<MemoryStore<TEntity>>(); |
| | 36 | 23 | | services.TryAddScoped<TStore>(); |
| | 36 | 24 | | 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 | | { |
| | 18 | 32 | | services.AddSingleton<ISerializationOptionsConfigurator, T>(); |
| | 18 | 33 | | return services; |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public IServiceCollection AddStartupTask<T>() where T : class, IStartupTask |
| | | 37 | | { |
| | 27 | 38 | | return services.AddScoped<IStartupTask, T>(); |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public IServiceCollection AddBackgroundTask<T>() where T : class, IBackgroundTask |
| | | 42 | | { |
| | 3 | 43 | | return services.AddScoped<IBackgroundTask, T>(); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public IServiceCollection AddRecurringTask<T>() where T : class, IRecurringTask |
| | | 47 | | { |
| | 9 | 48 | | return services.AddScoped<IRecurringTask, T>(); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public IServiceCollection AddRecurringTask<T>(TimeSpan interval) where T : class, IRecurringTask |
| | | 52 | | { |
| | 18 | 53 | | services.Configure<RecurringTaskOptions>(options => options.Schedule.ConfigureTask<T>(interval)); |
| | 9 | 54 | | return services.AddRecurringTask<T>(); |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |