![]() | Flash.Configuration is a configuration management tool that enables dynamic parsing and updating of configuration settings, including updating configuration files after build. |
|---|
- Dynamic configuration parsing: Supports parsing configuration files in JSON format. Extracts and structures configuration data for easy access.
- Automatic configuration updates: Updates configuration files dynamically based on specified rules. Ensures configurations remain up to date without manual intervention.
- Post-Build configuration handling: Automatically modifies configuration files after the application build process. Useful for adapting settings to different environments (e.g., development, staging, production).
- Environment-specific configurations: Manages different configuration files based on the target deployment environment. Allows seamless switching between settings for different use cases.
- Validation and Error Handling: Includes built-in validation mechanisms to detect and report misconfigurations. Logs errors and warnings for troubleshooting issues.
- Extensibility and Customization: Allows developers to define custom processing rules for configurations. Supports plug-in extensions to enhance functionality.
To add the Nuget package for the project type.
| Package | Project type |
|---|---|
| Flash.Configuration | Console Application, Web API, Class Library, Web API (native AOT), Worker service |
| Flash.Configuration.Wpf | WPF Application, WPF Class Library |
| Flash.Configuration.WinForms | Windows Forms App, Windows Forms Class Library |
To add the latest NuGet package:
Install-Package Flash.Configuration --version 8.0.0or
dotnet add package Flash.Configuration --version 8.0.0To add the latest NuGet package:
Install-Package Flash.Configuration.Wpf --version 8.0.0or
dotnet add package Flash.Configuration.Wpf --version 8.0.0To add the latest NuGet package:
Install-Package Flash.Configuration.WinForms --version 8.0.0or
dotnet add package Flash.Configuration.WinForms --version 8.0.0- .NET 8 or higher.
- Create a class for configuration
Sample
[FlashOrder(4)][FlashConfig("ConnectionStrings",environment:"Development")][FlashConfig("ConnectionStrings",environment:"Staging")]publicclassConnectionStrings{[FlashProperty("DefaultConnection")][FlashValue("Server=dev.localhost;Database=dev_db;User Id=dev_user;Password=******;",environment:"Development")][FlashValue("Server=staging.localhost;Database=staging_db;User Id=staging_user;Password=******;",environment:"Staging")]publicstringDefaultConnection{get;}=string.Empty;[FlashIgnore][FlashProperty("Enabled")][FlashValue(false,environment:"Development")][FlashValue(true,environment:"Staging")]publicboolEnabled{get;}}- Add the following configuration files to the project:
appsettings.Development.jsonappsettings.Staging.json
- Build the project;
- The configuration files should be updated:
appsettings.Development.json
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "ConnectionStrings": { "DefaultConnection": "Server=dev.localhost;Database=dev_db;User Id=dev_user;Password=******;" } }appsettings.Staging.json
{ "Logging": { "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } }, "ConnectionStrings": { "DefaultConnection": "Server=staging.localhost;Database=staging_db;User Id=staging_user;Password=******;" } }
- The configuration files should be updated:
- More samples are available with the link
FlashConfigmarks high-level configuration section for the environments:- Empty - should be applied the changes into file 'appSettings.json'
- Development - should be applied the changes into file 'appSettings.Development.json'
- Staging - should be applied the changes into file 'appSettings.Staging.json'
- Production - should be applied the changes into file 'appSettings.Production.json'
- You can use an other configuration name, i.e:
Test,Qa
Samples
[FlashConfig("ConnectionStrings",environment:"Development")]
Main section with name
ConnectionStringswill be available onDevelopmentenvironment[FlashConfig("ConnectionStrings")]
Main section with name
ConnectionStringswill be available for all environments (will be updated onlyappsettings.json)- Empty - should be applied the changes into file 'appSettings.json'
FlashPropertymarks a property in configuration section for the environments.Samples
[FlashProperty("DefaultConnection")]
The property has the name
DefaultConnectionwill be available for all environments[FlashProperty("MiddlewareSettings",isComplex:true)]
The property has the name
MiddlewareSettingswill be available for all environments and use the complex configuration. In the case, should use attributeFlashSectionFlashSectionmarks the complex configuration for the property in configuration section.Samples
[FlashSection]publicclassSettings{[FlashProperty("Skip-urls")]publicrequiredstring[]SkipUrls{get;set;}[FlashProperty("Health-urls")]publicrequiredstring[]HealthUrls{get;set;}}
The complex section will be available for the property
FlashValueallows set the default property for the property for the environments.Samples
[FlashValue("Server=dev.localhost;Database=dev_db;User Id=dev_user;Password=******;",environment:"Development")]
The value will be available on
Developmentenvironment.FlashValueIgnoreallows to ignore the default property for the property for the environments.Samples
[FlashValueIgnore("Development")]
The value will be ignored on
Developmentenvironment.FlashIgnoreallows to ignore the section/property/field/class on the environments. Available for all componentsSamples
[FlashIgnore]
FlashFieldmarks a field in configuration section for the environments.Samples
[FlashField("DefaultConnection")]
The field has the name
DefaultConnectionwill be available for all environments[FlashField("MiddlewareSettings")]
The field has the name
MiddlewareSettingswill be available for all environments and use the complex configuration.FlashOrderallows to set order of a component in configuration section for the environments.Samples
[FlashOrder(1)]
The component will be set first in the configuration for the environment
This project is licensed under the MIT License.
Supercharge Your .NET Configuration with Flash.Configuration
