using Elsa.Persistence.DocumentDb.Services; using Elsa.AutoMapper.Extensions; using Elsa.AutoMapper.Extensions.NodaTime; using Elsa.Extensions; using Elsa.Persistence.DocumentDb.Mapping; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Persistence.DocumentDb.Extensions { public static class ElsaOptionsExtensions { public static ElsaOptions UseCosmosDbWorkflowDefinitionStore(this ElsaOptions options, DocumentDbStorageOptions dbOptions) { options .AddCosmosDbProvider(dbOptions) .UseWorkflowDefinitionStore(sp => sp.GetRequiredService()); options.Services.AddSingleton(); return options; } public static ElsaOptions UseCosmosDbWorkflowInstanceStore(this ElsaOptions options, DocumentDbStorageOptions dbOptions) { options .AddCosmosDbProvider(dbOptions) .UseWorkflowInstanceStore(sp => sp.GetRequiredService()); options.Services.AddSingleton(); return options; } private static ElsaOptions AddCosmosDbProvider( this ElsaOptions options, DocumentDbStorageOptions documentDbOptions) { if (options.HasService()) return options; var storage = new DocumentDbStorage(documentDbOptions); options.Services .AddSingleton(storage) .AddAutoMapperProfile(ServiceLifetime.Singleton) .AddAutoMapperProfile(ServiceLifetime.Singleton); return options; } } }