using Microsoft.Data.SqlClient; using Microsoft.Data.Sqlite; using System.Data.Common; using System.Diagnostics; namespace EVCB_OCPP.DBAPI.ConnectionFactory; public class SqliteConnectionFactory : ISqliteConnectionConnectionFactory where T : class { private readonly ILogger> logger; public required string ConnectionString { get; init; } public SqliteConnectionFactory(ILogger> logger) { this.logger = logger; } public SqliteConnection Create() { var sqlConnection = new SqliteConnection(ConnectionString); sqlConnection.Open(); return sqlConnection; } public async Task CreateAsync() { var timer = Stopwatch.StartNew(); long t0, t1; var connectionStringBuilder = new SqliteConnectionStringBuilder(ConnectionString) {}; var sqlConnection = new SqliteConnection(connectionStringBuilder.ToString()); t0 = timer.ElapsedMilliseconds; await sqlConnection.OpenAsync(); t1 = timer.ElapsedMilliseconds; timer.Stop(); if (t1 > 500) { logger.LogWarning("{type} SqlConnection Open slow {create}/{open}", typeof(T), t0, t1); } return sqlConnection; } }