maple-Configuration.OptionsUpdateable
0.1.2
dotnet add package maple-Configuration.OptionsUpdateable --version 0.1.2
NuGet\Install-Package maple-Configuration.OptionsUpdateable -Version 0.1.2
<PackageReference Include="maple-Configuration.OptionsUpdateable" Version="0.1.2" />
<PackageVersion Include="maple-Configuration.OptionsUpdateable" Version="0.1.2" />
<PackageReference Include="maple-Configuration.OptionsUpdateable" />
paket add maple-Configuration.OptionsUpdateable --version 0.1.2
#r "nuget: maple-Configuration.OptionsUpdateable, 0.1.2"
#:package maple-Configuration.OptionsUpdateable@0.1.2
#addin nuget:?package=maple-Configuration.OptionsUpdateable&version=0.1.2
#tool nuget:?package=maple-Configuration.OptionsUpdateable&version=0.1.2
Configuration.OptionsUpdateable
The Configuration.OptionsUpdateable namespace provides a set of classes and interfaces that facilitate the management and updating of configuration options in a flexible and dynamic manner. This namespace is designed to help developers easily modify configuration settings at runtime without requiring application restarts.
Code Coverage
Code coverage for Configuration.OptionsUpdateable is automatically collected with each build:
- Pull Requests: Coverage summary and badge are posted as PR comments
- Workflow Runs: View coverage details in the workflow run summary on the Actions tab
- Detailed Reports: Download the full HTML coverage report from workflow artifacts
Key Features
Dynamic Updates: Allows for real-time updates to configuration options, enabling applications to adapt to changing requirements without downtime.
Type Safety: Utilizes strong typing to ensure that configuration options are valid and consistent throughout the application.
Validation Support: Integrates with validation mechanisms to ensure that updated configuration options meet predefined criteria. Functionality is based on FluentValidation library
Usage
To use the Configuration.OptionsUpdateable namespace, you typically start by defining your configuration options as a class. You can then register this class with the dependency injection container and use the provided interfaces to update the options as needed.
Working example can be found here:
using System;
using Configuration.OptionsUpdateable;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
// Define your configuration options class
public class MyConfigOptions : IConfigModel<MyConfigOptions>
{
public string SettingA { get; set; }
public int SettingB { get; set; }
public Position DeepClone()
{
// Create a deep copy of the current instance
// This is a simple example; for complex objects, ensure all nested objects are also cloned
return this with { };
}
}
// Register the options in the service collection
string configFolder = Path.Combine( System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "MyApp/Config");
builder.ConfigureUpdateableOptions(new UpdateableOptionsConfig
{
ConfigurationFolder = configFolder,
ValidateAtStartup = true,
Validators =
[
new PositionValidator()
]
});
// Inject IUpdateableOptions to update options at runtime
public class MyService
{
private readonly IUpdateableOptions<MyConfigOptions> _updateableOptions;
public MyService(IUpdateableOptions<MyConfigOptions> updateableOptions)
{
_updateableOptions = updateableOptions;
// _updateableOptions.Value returns updated information when callback is invoked
// (information is also updated without registering a callback)
_updateableOptions.RegisterUpdateNotification((updated) =>
{
Console.WriteLine($"Updated Position: {updated}");
HasReceivedUpdate = true;
});
}
public void UpdateSettings(string newSettingA, int newSettingB)
{
// local copy that can be modified
var options = _updateableOptions.Value;
// Update the settings
options.SettingA = newSettingA;
options.SettingB = newSettingB;
// modifications are updated in the underlying storage
_updateableOptions.Update(options);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FluentValidation (>= 12.1.1)
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 10.0.1)
- Microsoft.Extensions.Options (>= 10.0.1)
- System.IO.Abstractions (>= 22.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.