diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-29 08:03:27 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-01-29 08:03:27 -0600 |
| commit | 894458eaa695a44eed02e5c50190326428337cda (patch) | |
| tree | 17babc66bcf54b677041d560e7a8c6dbc5464c0e | |
| parent | 5c1cdfd24f4344bbc011a69b69979bfd5695e9aa (diff) | |
| download | slskd-894458eaa695a44eed02e5c50190326428337cda.tar.gz | |
docs and stuff
| -rw-r--r-- | src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs | 1 | ||||
| -rw-r--r-- | src/slskd/Common/Configuration/VolatileOverlayConfigurationSource.cs | 56 |
2 files changed, 52 insertions, 5 deletions
diff --git a/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs b/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs index 8cf62e91..f125b1fc 100644 --- a/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs +++ b/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs @@ -85,6 +85,7 @@ namespace slskd.Configuration /// </summary> public override void Load() { + // note: pretty much the same as VolatileOverlayConfigurationProvider; the two should be updated in lockstep void Map(Type type, string path) { var defaults = Activator.CreateInstance(type); diff --git a/src/slskd/Common/Configuration/VolatileOverlayConfigurationSource.cs b/src/slskd/Common/Configuration/VolatileOverlayConfigurationSource.cs index 9ae9c9ef..8707fe69 100644 --- a/src/slskd/Common/Configuration/VolatileOverlayConfigurationSource.cs +++ b/src/slskd/Common/Configuration/VolatileOverlayConfigurationSource.cs @@ -24,27 +24,44 @@ namespace slskd.Configuration using Microsoft.Extensions.Configuration; /// <summary> - /// A runtime patch <see cref="ConfigurationProvider"/>. + /// A <see cref="ConfigurationProvider"/> that provides a volatile, run-time overlay that supersedes other configuration + /// sources. /// </summary> + /// <remarks> + /// To use this provider as intended, the application must instantiate and store an instance of either <see cref="VolatileOverlayConfigurationProvider{T}"/> + /// or <see cref="VolatileOverlayConfigurationSource{T}"/>, and then invoke <see cref="Apply"/> with the desired overlay object. + /// </remarks> + /// <typeparam name="T">The Type of the overlay.</typeparam> public class VolatileOverlayConfigurationProvider<T> : ConfigurationProvider { + /// <summary> + /// Initializes a new instance of the <see cref="VolatileOverlayConfigurationProvider{T}"/> class. + /// </summary> public VolatileOverlayConfigurationProvider() { TargetType = typeof(T); Namespace = TargetType.Namespace.Split('.').First(); } - private T Current { get; set; } + /// <summary> + /// Gets the current overlay value. + /// </summary> + public T CurrentValue { get; private set; } + private string Namespace { get; set; } private Type TargetType { get; set; } + /// <summary> + /// Loads values from the <see cref="CurrentValue"/> overlay. + /// </summary> public override void Load() { - if (Current is null) + if (CurrentValue is null) { return; } + // note: pretty much the same as DefaultValueConfigurationProvider; the two should be updated in lockstep void Map(Type type, string path, object instance) { var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); @@ -82,28 +99,57 @@ namespace slskd.Configuration } } - Map(TargetType, Namespace, Current); + Map(TargetType, Namespace, CurrentValue); } + /// <summary> + /// Applies the goven <paramref name="overlay"/>. + /// </summary> + /// <param name="overlay">An object containing the values to overlay.</param> public void Apply(T overlay) { - Current = overlay; + CurrentValue = overlay; Load(); OnReload(); } } + /// <summary> + /// Represents values that are provided at run-time as an <see cref="IConfigurationSource"/>. + /// </summary> + /// <remarks> + /// To use this provider as intended, the application must instantiate and store an instance of either <see cref="VolatileOverlayConfigurationProvider{T}"/> + /// or <see cref="VolatileOverlayConfigurationSource{T}"/>, and then invoke <see cref="Apply"/> with the desired overlay object. + /// </remarks> + /// <typeparam name="T">The Type of the overlay.</typeparam> public class VolatileOverlayConfigurationSource<T> : IConfigurationSource { + /// <summary> + /// Initializes a new instance of the <see cref="VolatileOverlayConfigurationSource{T}"/> class. + /// </summary> public VolatileOverlayConfigurationSource() { Provider = new VolatileOverlayConfigurationProvider<T>(); } + /// <summary> + /// Gets the current overlay value. + /// </summary> + public T CurrentValue => Provider.CurrentValue; + private VolatileOverlayConfigurationProvider<T> Provider { get; set; } + /// <summary> + /// Applies the given <paramref name="overlay"/> to the underlying <see cref="VolatileOverlayConfigurationProvider{T}"/>. + /// </summary> + /// <param name="overlay">An object containing the values to overlay.</param> public void Apply(T overlay) => Provider.Apply(overlay); + /// <summary> + /// Builds the <see cref="VolatileOverlayConfigurationSource{T}"/> for this source. + /// </summary> + /// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param> + /// <returns>A <see cref="VolatileOverlayConfigurationProvider{T}"/>.</returns> public IConfigurationProvider Build(IConfigurationBuilder builder) { return Provider; |
