DataAccessProvider.PostgreSql
1.3.4
dotnet add package DataAccessProvider.PostgreSql --version 1.3.4
NuGet\Install-Package DataAccessProvider.PostgreSql -Version 1.3.4
<PackageReference Include="DataAccessProvider.PostgreSql" Version="1.3.4" />
<PackageVersion Include="DataAccessProvider.PostgreSql" Version="1.3.4" />
<PackageReference Include="DataAccessProvider.PostgreSql" />
paket add DataAccessProvider.PostgreSql --version 1.3.4
#r "nuget: DataAccessProvider.PostgreSql, 1.3.4"
#:package DataAccessProvider.PostgreSql@1.3.4
#addin nuget:?package=DataAccessProvider.PostgreSql&version=1.3.4
#tool nuget:?package=DataAccessProvider.PostgreSql&version=1.3.4
DataAccessProvider.Postgres
A PostgreSQL provider for the DataAccessProvider framework, built on top of the Npgsql driver. It offers async operations, parameterized queries, resilience support, and easy DI registration.
Installation
dotnet add package DataAccessProvider.Postgres
Configuration
Add a connection string named PostgresSource to your appsettings.json:
{
"ConnectionStrings": {
"PostgresSource": "Host=localhost;Port=5432;Database=mydb;Username=myuser;Password=mypassword"
}
}
Dependency Injection
// In Startup.cs or Program.cs
services.AddDataAccessProviderCore(configuration);
services.AddDataAccessProviderPostgres(configuration);
// After building the provider
serviceProvider.UseDataAccessProviderPostgres();
You can also register the provider with a raw connection string:
services.AddDataAccessProviderPostgres("Host=localhost;Port=5432;Database=mydb;Username=myuser;Password=mypassword");
Usage
var dataSourceProvider = serviceProvider.GetRequiredService<IDataSourceProvider>();
var queryParams = new PostgresSourceParams
{
Query = "SELECT id, name FROM users WHERE id = @id",
Parameters = new List<NpgsqlParameter>
{
new("@id", 1)
}
};
var result = await dataSourceProvider.ExecuteReaderAsync(queryParams);
Typed Results
public record User(int Id, string Name);
var typedParams = new PostgresSourceParams<User>
{
Query = "SELECT id, name FROM users"
};
var users = await dataSourceProvider.ExecuteReaderAsync(typedParams);
Managed Transactions
Resolve IDatabaseTransactionProvider<PostgresSourceParams> from the same DI scope and execute atomic work in its callback:
var transactionProvider = serviceProvider
.GetRequiredService<IDatabaseTransactionProvider<PostgresSourceParams>>();
await transactionProvider.ExecuteInTransactionAsync(async (transaction, cancellationToken) =>
{
await transaction.ExecuteNonQueryAsync(firstCommand, cancellationToken);
await transaction.ExecuteNonQueryAsync(secondCommand, cancellationToken);
}, IsolationLevel.ReadCommitted, cancellationToken);
Successful callbacks commit; exceptions and cancellation roll back. Commands share one connection, execute serially, and are not retried by the resilience policy. The callback executor cannot be reused after the callback completes.
Resilience
If you register an IResiliencePolicy (e.g., via AddDataAccessProviderCore), the provider will automatically apply retries/timeouts around database calls.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DataAccessProvider.Core (>= 1.3.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Npgsql (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.