using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace FlowScope.Config { public sealed class InMemoryConfigSource : IConfigSource { private readonly Dictionary _files; public InMemoryConfigSource( IReadOnlyDictionary files, string name = "InMemory") { _files = files != null ? new Dictionary(files) : throw new ArgumentNullException(nameof(files)); Name = string.IsNullOrWhiteSpace(name) ? throw new ArgumentException("Config source name is required.", nameof(name)) : name; } public string Name { get; } public Task LoadTextAsync(string fileName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!_files.TryGetValue(fileName, out var text)) { throw new InvalidOperationException($"Config file is missing: {fileName}"); } return Task.FromResult(text); } } }