Skip to content

Conversation

@adamsitnik
Copy link
Collaborator

@adamsitnik adamsitnik commented Sep 21, 2023

3 out of 4 DI extension methods are now ensuring that the DataSource is created only once (in a thread-safe way), and when it's possible they reuse the instance registered in the DI.

It's not an ideal fix, because the current design still allows the users to have more than one NpgsqlDataSource per their app. Example:

void Configure(IHostApplicationBuilder builder)
{
    builder.Services.AddNpgsqlDataSource("connectionString"); // registers a singleton factory for NpgsqlDataSource using Npgsql.DependencyInjection package, is used by the app
    builder.AddHealthChecks().AddNpgSql(new NpgSqlHealthCheckOptions()
    {
        ConnectionString = "connectionString" // registers a factory used only by the health check
    });
}

@unaizorrilla it's the fix I propose for 7.0.

For 8.0 we need to introduce a breaking change similar to what I did for the Azure clients in #2040

Contributes to #1993.

@adamsitnik adamsitnik added this to the V 7.1 milestone Sep 21, 2023
@github-actions github-actions bot added the test label Sep 21, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #2045 (796f47f) into master (a39d9fc) will decrease coverage by 0.94%.
Report is 1 commits behind head on master.
The diff coverage is 89.79%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##           master    #2045      +/-   ##
==========================================
- Coverage   66.72%   65.78%   -0.94%     
==========================================
  Files         262      174      -88     
  Lines        8439     4142    -4297     
  Branches      594      404     -190     
==========================================
- Hits         5631     2725    -2906     
+ Misses       2656     1325    -1331     
+ Partials      152       92      -60     
Flag Coverage Δ
AzureBlobStorage ?
AzureEventHubs ?
AzureFileStorage ?
AzureQueueStorage ?
AzureTableStorage ?
Dapr ?
Npgsql 41.28% <89.79%> (+12.54%) ⬆️
UI ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...ncyInjection/NpgSqlHealthCheckBuilderExtensions.cs 81.81% <89.79%> (+9.09%) ⬆️

... and 127 files with indirect coverage changes

@unaizorrilla unaizorrilla merged commit 418903e into Xabaril:master Oct 3, 2023
@adamsitnik adamsitnik deleted the npgSqlPerf branch October 16, 2023 07:44
@sungam3r
Copy link
Collaborator

sungam3r commented Dec 3, 2023

Current fix looks like more a hack than general-purpose solution.

@adamsitnik
Copy link
Collaborator Author

Current fix looks like more a hack than general-purpose solution.

I agree, that is why I wrote:

For 8.0 we need to introduce a breaking change similar to what I did for the Azure clients in

Related: #2096

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants