diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs b/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs index 87fdf26d7..385fb42b0 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs @@ -3,11 +3,9 @@ using System.Net.Mime; using System.Threading; using System.Threading.Tasks; using Elsa.Activities.Webhooks.Swagger.Examples; -using Elsa.Models; using Elsa.Persistence.Specifications; using Elsa.Server.Api.Models; using Elsa.Server.Api.Services; -using Elsa.Server.Api.Swagger.Examples; using Elsa.Webhooks.Models; using Elsa.Webhooks.Persistence; using Microsoft.AspNetCore.Http; @@ -41,7 +39,7 @@ namespace Elsa.Activities.Webhooks.Endpoints.WebhookDefinitions OperationId = "WebhookDefinitions.List", Tags = new[] { "WebhookDefinitions" }) ] - public async Task>> Handle(CancellationToken cancellationToken = default) + public async Task>> Handle(CancellationToken cancellationToken = default) { var specification = Specification.Identity; var items = await _store.FindManyAsync(specification, cancellationToken: cancellationToken); diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs index cb2ae5b18..af5e3f21c 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs @@ -31,7 +31,7 @@ namespace Elsa.Webhooks.Persistence.EntityFramework.Core if (string.IsNullOrWhiteSpace(connectionString)) connectionString = GetDefaultConnectionString(); - var webhookOptionsBuilder = new WebhookOptionsBuilder(elsa.Services); + var webhookOptionsBuilder = new WebhookOptionsBuilder(services); webhookOptionsBuilder.UseEntityFrameworkPersistence(options => Configure(options, connectionString)); services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp)); diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs index a2da08481..6c8b27ebb 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs @@ -17,12 +17,12 @@ namespace Elsa.Webhooks.Persistence.YesSql.Extensions { public static class WebhookServiceCollectionExtensions { - public static ElsaOptionsBuilder UseWebhookYesSqlPersistence(this ElsaOptionsBuilder elsa) => elsa.UseWebhookYesSqlPersistence(config => config.UseSqLite("Data Source=elsa.yessql.db;Cache=Shared", IsolationLevel.ReadUncommitted)); - public static ElsaOptionsBuilder UseWebhookYesSqlPersistence(this ElsaOptionsBuilder elsa, Action configure) => elsa.UseWebhookYesSqlPersistence((_, config) => configure(config)); + public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions) => webhookOptions.UseWebhookYesSqlPersistence(config => config.UseSqLite("Data Source=elsa.yessql.db;Cache=Shared", IsolationLevel.ReadUncommitted)); + public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions, Action configure) => webhookOptions.UseWebhookYesSqlPersistence((_, config) => configure(config)); - public static ElsaOptionsBuilder UseWebhookYesSqlPersistence(this ElsaOptionsBuilder elsa, Action configure) + public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions, Action configure) { - elsa.Services + webhookOptions.Services .AddScoped() .AddSingleton(sp => CreateStore(sp, configure)) .AddSingleton() @@ -34,11 +34,11 @@ namespace Elsa.Webhooks.Persistence.YesSql.Extensions .AddAutoMapperProfile() .AddIndexProvider(); - var webhookOptionsBuilder = new WebhookOptionsBuilder(elsa.Services); + var webhookOptionsBuilder = new WebhookOptionsBuilder(webhookOptions.Services); webhookOptionsBuilder.UseWebhookDefinitionStore(sp => sp.GetRequiredService()); - return elsa; + return webhookOptions; } private static IStore CreateStore( diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs index bfa638599..7ad3f1235 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs @@ -1,8 +1,13 @@ using System; +using Elsa.Activities.Webhooks; +using Elsa.Activities.Webhooks.Persistence.Decorators; using Elsa.Attributes; using Elsa.Services.Startup; +//using Elsa.Webhooks.Persistence.EntityFramework.Core.Extensions; +//using Elsa.Webhooks.Persistence.YesSql.Extensions; using Elsa.Webhooks.Persistence.YesSql.Extensions; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using YesSql.Provider.MySql; using YesSql.Provider.PostgreSql; using YesSql.Provider.Sqlite; @@ -45,6 +50,7 @@ namespace Elsa.Webhooks.Persistence.YesSql public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration) { + var services = elsa.Services; var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}"); var connectionStringName = section.GetValue("ConnectionStringName"); var connectionString = section.GetValue("ConnectionString"); @@ -60,7 +66,15 @@ namespace Elsa.Webhooks.Persistence.YesSql if (string.IsNullOrWhiteSpace(connectionString)) connectionString = GetDefaultConnectionString(); - elsa.UseWebhookYesSqlPersistence(options => Configure(options, connectionString)); + //elsa.UseWebhookYesSqlPersistence(options => Configure(options, connectionString)); + + var webhookOptionsBuilder = new WebhookOptionsBuilder(services); + webhookOptionsBuilder.UseWebhookYesSqlPersistence(options => Configure(options, connectionString)); + + services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp)); + + services.Decorate(); + services.Decorate(); } protected virtual string GetDefaultConnectionString() => throw new Exception($"No connection string specified for the {ProviderName} provider"); diff --git a/src/samples/server/Elsa.Samples.Server.Host/README.md b/src/samples/server/Elsa.Samples.Server.Host/README.md index 03d1e1f64..b690a8e02 100644 --- a/src/samples/server/Elsa.Samples.Server.Host/README.md +++ b/src/samples/server/Elsa.Samples.Server.Host/README.md @@ -90,6 +90,35 @@ YesSql Postgre } ``` +### Configure modular activity providers such as Webhooks +It is required to add modular activity provider and additional persistence feature for your modular activity provider. +The persistence providers should match for Elsa Core and modular activity providers. +Two examples below are given to set up Elsa Core and Webhooks persistence as follow. + +EF Sqlite +``` +"Elsa": { +"Features": [ + "Persistence:EntityFrameworkCore:Sqlite", + "Webhooks" + "Webhooks:Persistence:EntityFrameworkCore:Sqlite", + ... + ], +} +``` + +EF MongoDB +``` +"Elsa": { +"Features": [ + "Persistence:MongoDb", + "Webhooks" + "Webhooks:Persistence:MongoDb", + ... + ], +} +``` + ### Configure connection strings for each persistence ``` @@ -102,7 +131,7 @@ YesSql Postgre }, ``` -### Connection string examples +### Connection strings MySql https://www.connectionstrings.com/mysql/ SQL Server diff --git a/src/samples/server/Elsa.Samples.Server.Host/appsettings.json b/src/samples/server/Elsa.Samples.Server.Host/appsettings.json index 700ab42e2..bb94da846 100644 --- a/src/samples/server/Elsa.Samples.Server.Host/appsettings.json +++ b/src/samples/server/Elsa.Samples.Server.Host/appsettings.json @@ -13,12 +13,12 @@ "Redis": "localhost:6379,abortConnect=false", "MySql": "Server=LAPTOP-B76STK67;Database=Elsa;Uid=myUsername;Pwd=myPassword;", "SqlServer": "Server=LAPTOP-B76STK67;Database=Elsa;Integrated Security=true;MultipleActiveResultSets=True;Max Pool Size=500;Connection Timeout=3600", - "Sqlite": "Data Source=elsa.sqlite.db;Cache=Shared;", + "Sqlite": "Data Source=elsa.sqlite.yes.db;Cache=Shared;", "MongoDb": "mongodb://localhost:27017/Elsa" }, "Elsa": { "Features": [ - "Persistence:EntityFrameworkCore:Sqlite", + "Persistence:YesSql:Sqlite", "Console", "Http", "Email", @@ -27,7 +27,7 @@ "UserTask", "Conductor", "Webhooks", - "Webhooks:Persistence:EntityFrameworkCore:Sqlite" + "Webhooks:Persistence:YesSql:Sqlite" ], "Persistence:MySql": { "ConnectionStringName": "MySql"