using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System.Collections.Concurrent; namespace zero.Configuration; public class ZeroOptions : IZeroOptions { protected IServiceProvider ServiceProvider { get; set; } protected ConcurrentDictionary OptionsCache { get; private set; } = new(); public ZeroOptions(IServiceProvider serviceProvider) { Version = "0.0.1-alpha.1"; ServiceProvider = serviceProvider; //SupportedLanguages = new string[2] { "en-US", "de-DE" }; //DefaultLanguage = SupportedLanguages[0]; //TokenExpiration = 60 * 3; //BackofficePath = "/zero"; //ExcludedPaths = new() { }; //Raven = new() //{ // CollectionPrefix = String.Empty //}; } /// public TOptions For() where TOptions : class { Type type = typeof(TOptions); if (!OptionsCache.TryGetValue(type, out object value)) { IOptions options = ServiceProvider.GetService>(); value = options.Value; OptionsCache.TryAdd(type, value); } return value as TOptions; } /// public bool Initialized => !String.IsNullOrEmpty(For()?.Database); /// public string Version { get; private set; } ///// //public string DefaultLanguage { get; set; } ///// //public string[] SupportedLanguages { get; private set; } ///// //public int TokenExpiration { get; set; } ///// //public RavenOptions Raven { get; set; } ///// //public ApplicationOptions Applications { get; set; } ///// //public FeatureOptions Features { get; private set; } ///// //public PageOptions Pages { get; private set; } ///// //public ModuleOptions Modules { get; private set; } ///// //public SettingsOptions Settings { get; private set; } ///// //public SpaceOptions Spaces { get; private set; } ///// //public IntegrationOptions Integrations { get; private set; } ///// //public BlueprintOptions Blueprints { get; private set; } } public interface IZeroOptions { /// /// The currently active version /// This should not be set manually, as it is used for setup and migrations and incremented automatically /// string Version { get; } /// /// Whether this zero instance is initialized (setup is completed) /// bool Initialized { get; } /// /// Get typed options (proxy to IOptions) /// TOptions For() where TOptions : class; ///// ///// Default language ISO code ///// //string DefaultLanguage { get; set; } ///// ///// Language ISO codes which are supported by the zero backoffice ///// //string[] SupportedLanguages { get; } ///// ///// Expiration in minutes of a generated change token for an entity ///// //int TokenExpiration { get; set; } ///// ///// RavenDB configuration data ///// //RavenOptions Raven { get; set; } ///// ///// Application options ///// //ApplicationOptions Applications { get; set; } }