Files
mixtape/zero.Core/Configuration/ZeroOptions.cs
T

136 lines
3.4 KiB
C#
Raw Normal View History

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