Repository navigation
fix(postgresql): register NpgsqlDataSource as a keyed service - #48
Merged
Merged
Conversation
The provider registered its data source as an unkeyed NpgsqlDataSource singleton, which collided with a data source registered by the application: depending on the registration order, either the application queries went to the keys database or the keys went to the application database. The instance registration also prevented the container from disposing it. Register the data source as a keyed singleton created by a factory, so the container owns and disposes it, and resolve it in the repository with [FromKeyedServices]. The public repository constructor is unchanged. A malformed connection string now fails when the data source is first resolved (UseDapperDataProtection) instead of at registration. Closes #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PersistKeysWithDapperInPostgreSQLregistered its data source as an unkeyedNpgsqlDataSourcesingleton, which collided with a data source registered by the application (for example withAddNpgsqlDataSource): the last registration won, silently routing either the application queries or the keys to the wrong database. The instance registration also meant the container never disposed it.Constants.DataSourceServiceKey), created by a factory so the container owns and disposes it.PostgreSQLDataProtectionRepositorywith[FromKeyedServices]; the public constructor signature is unchanged.Behavior changes
NpgsqlDataSourceregistered by this provider, without registering its own, now gets a resolution error. This relied on the bug, so it is not marked as breaking.UseDapperDataProtection()at startup) instead of at registration, as with the SQL Server provider.Tests
NpgsqlDataSourceregistration; the data source is disposed with the service provider; theIncludeErrorDetailtest now resolves the keyed instance.Closes #19