using MMoneyCoderSharp.Data; namespace MBN_STOCK_WEBVIEW.Infrastructure; public sealed class DatabaseRuntime { private DatabaseRuntime( DatabaseOptions options, IDatabaseConnectionFactory connectionFactory, IDataQueryExecutor executor, IDatabaseHealthService healthService) { Options = options; ConnectionFactory = connectionFactory; Executor = executor; HealthService = healthService; } public DatabaseOptions Options { get; } public IDatabaseConnectionFactory ConnectionFactory { get; } public IDataQueryExecutor Executor { get; } public IDatabaseHealthService HealthService { get; } public static DatabaseRuntime CreateDefault(string? configurationPath = null) { var options = new DatabaseOptionsLoader().Load(configurationPath); return Create(options); } public static DatabaseRuntime Create(DatabaseOptions options) { ArgumentNullException.ThrowIfNull(options); options.Normalize(); options.ValidateRuntimeSettings(); var connectionFactory = new ProviderDatabaseConnectionFactory(options); var executor = new ResilientDataQueryExecutor(connectionFactory, options.Resilience); var healthService = new DatabaseHealthService(executor, options); return new DatabaseRuntime(options, connectionFactory, executor, healthService); } }