using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System.Collections.Concurrent; namespace Finch.Configuration; public class FinchOptions : IFinchOptions { /// public string Version { get; set; } /// public string Language { get; set; } = "en_US"; /// public string AppName { get; set; } /// public TimeSpan TokenExpiration { get; set; } internal IServiceProvider ServiceProvider { get; set; } protected ConcurrentDictionary OptionsCache { get; } = new(); /// public TOptions For() where TOptions : class { Type type = typeof(TOptions); if (!OptionsCache.TryGetValue(type, out object value) && ServiceProvider != null) { IOptions options = ServiceProvider.GetService>(); value = options.Value; OptionsCache.TryAdd(type, value); } return value as TOptions; } } public interface IFinchOptions { /// /// The currently active version /// This should not be set manually, as it is used for setup and migrations and incremented automatically /// string Version { get; set; } /// /// ISO Code for language /// public string Language { get; set; } /// /// Name of the app (used in logging and otehr areas) /// public string AppName { get; set; } /// /// Expiration of a generated change token for an entity /// TimeSpan TokenExpiration { get; set; } /// /// Get typed options (proxy to IOptions) /// TOptions For() where TOptions : class; }