akkadotnet / Akka.Persistence.PostgreSql

Akka.Persistence.PostgreSql provider
Apache License 2.0
32 stars 35 forks source link

Implement DbDataSource #170

Open CumpsD opened 1 year ago

CumpsD commented 1 year ago

Describe the solution you'd like

https://www.npgsql.org/doc/release-notes/7.0.html#dbdatasource

Make use of the new NpgsqlDataSource from Npgsql, which allows things on a higher level

CumpsD commented 1 year ago

How about something like:

        private static readonly ConcurrentDictionary<string, NpgsqlDataSource> DataSources = new();

        protected override DbConnection CreateDbConnection(string connectionString)
        {
            var dataSource = DataSources.GetOrAdd(connectionString,
                x =>
                {
                    var dataSourceBuilder = new NpgsqlDataSourceBuilder(x);
                    // Possibly provide extension method here?
                    return dataSourceBuilder.Build();
                });

            return dataSource.CreateConnection();
        }