feat: complete Oracle and MariaDB WebView data layer
This commit is contained in:
44
src/MBN_STOCK_WEBVIEW.Infrastructure/DatabaseRuntime.cs
Normal file
44
src/MBN_STOCK_WEBVIEW.Infrastructure/DatabaseRuntime.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user