A module that makes it possible to conditionally enable and conditionally keep enabled, or entirely prevent enabling, configurable sets of features on tenants.
- To use this feature, enable it on both the Default and the user tenant.
- Features that should be conditionally enabled, as well as the features whose status acts as the condition, can be specified either in appsettings.json using
ConditionallyEnabledFeaturesOptions
or inProgram
via theConfigureFeaturesGuard()
orConfigureFeaturesGuardWithoutOverriding()
extension method. Conditionally enabled features need to be provided with a singular or multiple condition features, where the status of the condition features determines whether the corresponding conditional feature is enabled or disabled. Example configuration:
Program
config example:
builder.Services
.AddOrchardCms(orchardCoreBuilder =>
orchardCoreBuilder.ConfigureFeaturesGuard(
new Dictionary<string, IEnumerable<string>>
{
// "Enable this feature and keep it enabled": "If any of these features are enabled",
["OrchardCore.Media.Azure.Storage"] = new[] { "OrchardCore.Media" },
["OrchardCore.Twitter"] = new[] { "Lombiq.UIKit", "Lombiq.ChartJs" },
}));
ConfigureFeaturesGuardForAzureStorage()
is available to addAzure Storage
as a conditional feature andMedia
as its condition feature.ConfigureFeaturesGuardForElasticsearch()
is available to addElasticsearch
as a conditional feature andIndexing
orSearch
as its condition feature.
appsettings.json config example:
{
"OrchardCore": {
"Lombiq_Hosting_Tenants_FeaturesGuard": {
"ConditionallyEnabledFeaturesOptions": {
"ConditionallyEnabledFeatures": {
"EnableFeatureIfOtherFeatureIsEnabled": {
// "Enable this feature and keep it enabled": "If any of these features are enabled",
"OrchardCore.Media.Azure.Storage": "OrchardCore.Media",
"OrchardCore.Twitter": "OrchardCore.Media, OrchardCore.Workflows"
}
}
}
},
}
Example case 1:
- Enables
Azure Storage
whenMedia
is enabled. KeepsAzure Storage
enabled as long asMedia
is enabled.
Example case 2:
- Enables
Twitter
whenMedia
orWorkflows
is enabled. KeepsTwitter
enabled as long as eitherMedia
orWorkflows
remains enabled.
- Preventing enabling certain features on user tenants is possible via recipes in a
FeatureProfiles
step. For more on the Feature Profiles feature, see the official documentation. Example configuration:
{
"name": "FeatureProfiles",
"FeatureProfiles": {
"Features Guard": {
"FeatureRules": [
{
"Rule": "Exclude",
"Expression": "OrchardCore.Workflows.Session"
},
{
"Rule": "Exclude",
"Expression": "OrchardCore.Search.Lucene"
},
{
"Rule": "Exclude",
"Expression": "OrchardCore.MiniProfiler"
},
{
"Rule": "Exclude",
"Expression": "Lombiq.Tests.UI.Shortcuts"
}
]
}
}
}