Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DbDataSource #170

Open
CumpsD opened this issue Dec 7, 2022 · 1 comment
Open

Implement DbDataSource #170

CumpsD opened this issue Dec 7, 2022 · 1 comment

Comments

@CumpsD
Copy link
Member

CumpsD commented Dec 7, 2022

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
Copy link
Member Author

CumpsD commented Dec 7, 2022

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();
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant