Skip to main content
Version: Next

Module Extension Configuration

1. Overview​

Module extension configuration allows plugins or external modules to modify the behavior or configuration of the host program without changing the host code. This is usually achieved through the Options pattern (Options Pattern) and configuration files.

2. Configuration Definition​

Modules can define their own configuration classes (Options classes).

public class MyPluginOptions
{
public bool EnableFeatureX { get; set; }
public int MaxRetryCount { get; set; }
}

3. Configuration Loading​

In the ConfigureServices method of the module, bind the configuration section.

public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();

Configure<MyPluginOptions>(configuration.GetSection("MyPlugin"));
}

4. Configuration Overriding​

The host application can override the default settings of the plugin module in its appsettings.json.

{
"MyPlugin": {
"EnableFeatureX": true,
"MaxRetryCount": 5
}
}

5. Dynamic Configuration (PreConfigure)​

ABP provides a PreConfigureServices mechanism allowing the host to modify the configuration logic of the module before the module's ConfigureServices executes.

// In the Host's Module
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<MyPluginOptions>(options =>
{
options.EnableFeatureX = true;
});
}

6. Extension Management UI​

For complex module configurations, plugins can provide Settings Management interfaces (implementing ISettingDefinitionProvider) allowing administrators to modify configurations at runtime via the UI, storing them in the database.

public class MyPluginSettingDefinitionProvider : SettingDefinitionProvider
{
public override void Define(ISettingDefinitionContext context)
{
context.Add(
new SettingDefinition("MyPlugin.FeatureX.Enabled", "true"),
new SettingDefinition("MyPlugin.MaxRetries", "3")
);
}
}