Stop using arrays for Features in the appsettings
Stop using arrays for Features in the appsettings
This commit is contained in:
parent
0bd5b8f743
commit
e00fc41887
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ namespace Elsa
|
|||
|
||||
public Type DefaultWorkflowStorageProviderType { get; set; }
|
||||
public WorkflowChannelOptions WorkflowChannelOptions { get; set; } = new();
|
||||
public FeatureOptions FeatureOptions { get; set; } = new();
|
||||
|
||||
internal Func<IServiceProvider, IBlobStorage> StorageFactory { get; set; }
|
||||
internal Func<IServiceProvider, IWorkflowDefinitionStore> WorkflowDefinitionStoreFactory { get; set; }
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ 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;
|
||||
|
|
@ -64,6 +65,26 @@ namespace Elsa
|
|||
return this;
|
||||
}
|
||||
|
||||
public ElsaOptionsBuilder ConfigureFeatures(IConfigurationSection configuration)
|
||||
{
|
||||
ElsaOptions.FeatureOptions.Features = new Dictionary<string, bool>();
|
||||
var features = configuration.AsEnumerable();
|
||||
|
||||
foreach (var feature in features)
|
||||
{
|
||||
if (feature.Key.EndsWith(":ConnectionStringName")) continue;
|
||||
|
||||
if (feature.Value != null && bool.Parse(feature.Value))
|
||||
{
|
||||
ElsaOptions.FeatureOptions.Features.Add(feature.Key
|
||||
.Replace("Elsa:Features:", string.Empty)
|
||||
.Replace(":Enabled", string.Empty), true);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElsaOptionsBuilder AddActivity<T>() where T : IActivity => AddActivity(typeof(T));
|
||||
|
||||
public ElsaOptionsBuilder AddActivity(Type activityType)
|
||||
|
|
|
|||
|
|
@ -10,17 +10,18 @@ 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)
|
||||
{
|
||||
var enabledFeatures = features.ToHashSet();
|
||||
var enabledFeatures = builder.ElsaOptions.FeatureOptions.Features.ToHashSet();
|
||||
|
||||
var startupTypesQuery = from assembly in assemblies
|
||||
from type in assembly.GetExportedTypes()
|
||||
where type.IsClass && !type.IsAbstract && typeof(IStartup).IsAssignableFrom(type)
|
||||
let featureAttribute = type.GetCustomAttribute<FeatureAttribute>()
|
||||
where featureAttribute != null && enabledFeatures.Contains(featureAttribute.FeatureName)
|
||||
let enabledFeature = enabledFeatures.FirstOrDefault(x => x.Key == featureAttribute.FeatureName && x.Value)
|
||||
where featureAttribute != null && !enabledFeature.Equals(default(KeyValuePair<string, bool>))
|
||||
select type;
|
||||
|
||||
var startupTypes = startupTypesQuery.ToList();
|
||||
|
|
|
|||
9
src/core/Elsa.Core/FeatureOptions.cs
Normal file
9
src/core/Elsa.Core/FeatureOptions.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Elsa
|
||||
{
|
||||
public class FeatureOptions
|
||||
{
|
||||
public Dictionary<string, bool>? Features { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
using System.Collections.Generic;
|
||||
using Elsa.Samples.Server.Host.Activities;
|
||||
using Elsa.Server.Hangfire.Extensions;
|
||||
using Hangfire;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
|
@ -7,6 +5,8 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elsa.Samples.Server.Host
|
||||
{
|
||||
|
|
@ -67,7 +67,8 @@ namespace Elsa.Samples.Server.Host
|
|||
.AddElsa(elsa => elsa
|
||||
.AddActivitiesFrom<Startup>()
|
||||
.AddWorkflowsFrom<Startup>()
|
||||
.AddFeatures(startups, Configuration, elsaSection.GetSection("Features").Get<List<string>>())
|
||||
.ConfigureFeatures(elsaSection.GetSection("Features"))
|
||||
.AddFeatures(startups, Configuration)
|
||||
.ConfigureWorkflowChannels(options => elsaSection.GetSection("WorkflowChannels").Bind(options))
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,34 +18,45 @@
|
|||
"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": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Console": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Http": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Email": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Temporal:Quartz": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"JavaScript:Activities": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"UserTask": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Conductor": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Telnyx": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Webhooks": {
|
||||
"Enabled": "true"
|
||||
},
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite": {
|
||||
"Enabled": "true",
|
||||
"ConnectionStringName": "Sqlite"
|
||||
}
|
||||
},
|
||||
"WorkflowChannels": {
|
||||
"Channels": [
|
||||
|
|
|
|||
Loading…
Reference in a new issue