Merge pull request #1219 from elsa-workflows/arrays_in_appsettings
Arrays in appsettings
This commit is contained in:
commit
20c4df0d14
|
|
@ -16,7 +16,7 @@ namespace Elsa.Webhooks.Persistence.EntityFramework.Core
|
|||
public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration)
|
||||
{
|
||||
var services = elsa.Services;
|
||||
var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}");
|
||||
var section = configuration.GetSection($"Elsa:Features:Webhooks:Persistence:EntityFrameworkCore:{ProviderName}");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Elsa.Activities.Webhooks;
|
||||
using Elsa.Activities.Webhooks.Persistence.Decorators;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Persistence.MongoDb.Options;
|
||||
using Elsa.Services.Startup;
|
||||
using Elsa.Webhooks.Persistence.MongoDb.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
@ -15,7 +14,7 @@ namespace Elsa.Webhooks.Persistence.MongoDb
|
|||
public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration)
|
||||
{
|
||||
var services = elsa.Services;
|
||||
var section = configuration.GetSection($"Elsa:Persistence:MongoDb");
|
||||
var section = configuration.GetSection($"Elsa:Features:Webhooks:Persistence:MongoDb");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,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 section = configuration.GetSection($"Elsa:Features:Webhooks:Persistence:YesSql:{ProviderName}");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Caching;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence;
|
||||
using Elsa.Providers.WorkflowStorage;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Messaging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json;
|
||||
using Rebus.DataBus.InMem;
|
||||
|
|
|
|||
|
|
@ -10,14 +10,16 @@ namespace Elsa
|
|||
{
|
||||
public static class ElsaOptionBuilderExtensions
|
||||
{
|
||||
public static ElsaOptionsBuilder AddFeatures(this ElsaOptionsBuilder builder, IEnumerable<Type> assemblyMarkerTypes, IConfiguration configuration, IEnumerable<string> features) => AddFeatures(builder, GetAssemblies(assemblyMarkerTypes), configuration, features);
|
||||
public static ElsaOptionsBuilder AddFeatures(this ElsaOptionsBuilder builder, IEnumerable<Type> assemblyMarkerTypes, IConfiguration configuration) => AddFeatures(builder, GetAssemblies(assemblyMarkerTypes), configuration);
|
||||
|
||||
public static ElsaOptionsBuilder AddFeatures(this ElsaOptionsBuilder builder, IEnumerable<Assembly> assemblies, IConfiguration configuration, IEnumerable<string> features)
|
||||
public static ElsaOptionsBuilder AddFeatures(this ElsaOptionsBuilder builder, IEnumerable<Assembly> assemblies, IConfiguration configuration)
|
||||
{
|
||||
if (features == null!) // Null when configuration binding finds an empty array.
|
||||
var enabledFeatures = ParseFeatures(configuration);
|
||||
|
||||
if (enabledFeatures == null!) // Null when configuration binding finds an empty array.
|
||||
return builder;
|
||||
|
||||
var enabledFeatures = features.ToHashSet();
|
||||
|
||||
enabledFeatures = enabledFeatures.ToHashSet();
|
||||
|
||||
var startupTypesQuery = from assembly in assemblies
|
||||
from type in assembly.GetExportedTypes()
|
||||
|
|
@ -37,7 +39,36 @@ namespace Elsa
|
|||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<string> ParseFeatures(IConfiguration configuration)
|
||||
{
|
||||
var elsaFeaturesSection = "Elsa:Features";
|
||||
var features = configuration.GetSection(elsaFeaturesSection).AsEnumerable();
|
||||
|
||||
return
|
||||
from feature in features
|
||||
let isEnabled = ParseFeatureFlag(configuration, feature.Key)
|
||||
where isEnabled
|
||||
select feature.Key.Replace($"{elsaFeaturesSection}:", string.Empty);
|
||||
}
|
||||
|
||||
private static bool ParseFeatureFlag(IConfiguration configuration, string feature)
|
||||
{
|
||||
if (configuration.GetSection($"{feature}:Enabled").Exists())
|
||||
{
|
||||
bool.TryParse(configuration.GetValue<string>($"{feature}:Enabled"), out var enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
if (!feature.EndsWith(":Enabled"))
|
||||
{
|
||||
bool.TryParse(configuration.GetValue<string>($"{feature}"), out var enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static IEnumerable<Assembly> GetAssemblies(IEnumerable<Type> assemblyMarkerTypes) => assemblyMarkerTypes.Select(x => x.Assembly).Distinct();
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace Elsa.Persistence.EntityFramework.Core
|
|||
|
||||
public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration)
|
||||
{
|
||||
var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}");
|
||||
var section = configuration.GetSection($"Elsa:Features:Persistence:EntityFrameworkCore:{ProviderName}");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Elsa.Persistence.MongoDb
|
|||
{
|
||||
public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration)
|
||||
{
|
||||
var section = configuration.GetSection($"Elsa:Persistence:MongoDb");
|
||||
var section = configuration.GetSection($"Elsa:Features:Persistence:MongoDb");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Elsa.Persistence.YesSql
|
|||
|
||||
public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration)
|
||||
{
|
||||
var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}");
|
||||
var section = configuration.GetSection($"Elsa:Features:Persistence:YesSql:{ProviderName}");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace ElsaDashboard.Samples.AspNetCore.Monolith
|
|||
.AddQuartzTemporalActivities()
|
||||
.AddJavaScriptActivities()
|
||||
.AddActivitiesFrom<Startup>()
|
||||
.AddFeatures(new[] { typeof(Startup) }, Configuration, elsaSection.GetSection("Features").Get<List<string>>())
|
||||
.AddFeatures(new[] { typeof(Startup) }, Configuration)
|
||||
);
|
||||
|
||||
services
|
||||
|
|
|
|||
|
|
@ -1,93 +1,104 @@
|
|||
### Configure persistence in appsettings.json
|
||||
### Configure persistence for Elsa Core in the appsettings.json
|
||||
|
||||
It is required to specify the persistence, it's enabled status and connection string name in Features
|
||||
|
||||
EF Sqlite
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:Sqlite",
|
||||
"Features": {
|
||||
"Persistence:EntityFrameworkCore:Sqlite": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "Sqlite"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
EF MySQL
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:MySql",
|
||||
"Features": {
|
||||
"Persistence:EntityFrameworkCore:MySql": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "MySql"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
EF SQL Server
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:SqlServer",
|
||||
...
|
||||
],
|
||||
}
|
||||
"Features": {
|
||||
"Persistence:EntityFrameworkCore:SqlServer": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "SqlServer"
|
||||
},
|
||||
...
|
||||
```
|
||||
|
||||
EF Postgre
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:PostgreSql",
|
||||
"Features": {
|
||||
"Persistence:EntityFrameworkCore:PostgreSql": {
|
||||
"Enabled": "true",
|
||||
"ConnectionStringName": "PostgreSql"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
EF MongoDB
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:MongoDb",
|
||||
"Features": {
|
||||
"Persistence:MongoDb": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "MongoDb"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
YesSql Sqlite
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:YesSql:Sqlite",
|
||||
"Features": {
|
||||
"Persistence:YesSql:Sqlite": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "Sqlite"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
YesSql MySQL
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:YesSql:MySql",
|
||||
"Features": {
|
||||
"Persistence:YesSql:MySql": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "MySql"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
YesSql SQL Server
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:YesSql:SqlServer",
|
||||
"Features": {
|
||||
"Persistence:YesSql:SqlServer": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "SqlServer"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
YesSql Postgre
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:YesSql:PostgreSql",
|
||||
"Features": {
|
||||
"Persistence:YesSql:PostgreSql": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "PostgreSql"
|
||||
},
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### Configure modular activity providers such as Webhooks
|
||||
|
|
@ -98,25 +109,35 @@ Two examples below are given to set up Elsa Core and Webhooks persistence as fol
|
|||
EF Sqlite
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:Sqlite",
|
||||
"Webhooks"
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite",
|
||||
"Features": {
|
||||
"Persistence:EntityFrameworkCore:Sqlite": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "Sqlite"
|
||||
},
|
||||
"Webhooks": true
|
||||
},
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "Sqlite"
|
||||
}
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
EF MongoDB
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:MongoDb",
|
||||
"Webhooks"
|
||||
"Webhooks:Persistence:MongoDb",
|
||||
"Features": {
|
||||
"Persistence:MongoDb": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "MongoDb"
|
||||
},
|
||||
"Webhooks": true
|
||||
},
|
||||
"Webhooks:Persistence:MongoDb": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "MongoDb"
|
||||
}
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### Configure connection strings for each persistence
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ namespace Elsa.Samples.Server.Host
|
|||
.AddElsa(elsa => elsa
|
||||
.AddActivitiesFrom<Startup>()
|
||||
.AddWorkflowsFrom<Startup>()
|
||||
.AddFeatures(startups, Configuration, elsaSection.GetSection("Features").Get<List<string>>())
|
||||
.AddFeatures(startups, Configuration)
|
||||
.ConfigureWorkflowChannels(options => elsaSection.GetSection("WorkflowChannels").Bind(options))
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,34 +18,25 @@
|
|||
"PostgreSql": "Server=127.0.0.1;Port=5432;Database=elsa;User Id=postgres;Password=password;"
|
||||
},
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:Sqlite",
|
||||
"Dispatcher:Hangfire",
|
||||
"Console",
|
||||
"Http",
|
||||
"Email",
|
||||
"Temporal:Quartz",
|
||||
"JavaScript:Activities",
|
||||
"UserTask",
|
||||
"Conductor",
|
||||
"Telnyx",
|
||||
"Webhooks",
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite"
|
||||
],
|
||||
"Persistence:MySql": {
|
||||
"ConnectionStringName": "MySql"
|
||||
},
|
||||
"Persistence:SqlServer": {
|
||||
"ConnectionStringName": "SqlServer"
|
||||
},
|
||||
"Persistence:Sqlite": {
|
||||
"ConnectionStringName": "Sqlite"
|
||||
},
|
||||
"Persistence:MongoDb": {
|
||||
"ConnectionStringName": "MongoDb"
|
||||
},
|
||||
"Persistence:PostgreSql": {
|
||||
"ConnectionStringName": "PostgreSql"
|
||||
"Features": {
|
||||
"Persistence:EntityFrameworkCore:Sqlite": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "Sqlite"
|
||||
},
|
||||
"Dispatcher:Hangfire": true,
|
||||
"Console": true,
|
||||
"Http": true,
|
||||
"Email": true,
|
||||
"Temporal:Quartz": true,
|
||||
"JavaScript:Activities": true,
|
||||
"UserTask": true,
|
||||
"Conductor": true,
|
||||
"Telnyx": true,
|
||||
"Webhooks": true,
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite": {
|
||||
"Enabled": true,
|
||||
"ConnectionStringName": "Sqlite"
|
||||
}
|
||||
},
|
||||
"WorkflowChannels": {
|
||||
"Channels": [
|
||||
|
|
|
|||
Loading…
Reference in a new issue