Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 7341174

Browse files
author
Angelo Pirola
committed
Aggiunta documentazione Postgres DbContextPool
1 parent 88d11bd commit 7341174

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Entity Framework Core DbContext Pool configuration for Postgres database
2+
3+
4+
## Configuration to add to the appsettings.json file
5+
6+
```json
7+
"ConnectionStrings": {
8+
"Default": "Host=[SERVER];Port=5432;Database=[DATABASE];Username=[USERNAME];Password=[PASSWORD]"
9+
},
10+
```
11+
12+
<b>Note:</b> The default port for Postgres is 5432, but it can be changed as needed according to your needs.
13+
14+
15+
## Registering services at Startup
16+
17+
```csharp
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
public void ConfigureServices(IServiceCollection services)
26+
{
27+
//OMISSIS
28+
29+
var connectionString = Configuration.GetSection("ConnectionStrings").GetValue<string>("Default");
30+
31+
//OMISSIS
32+
33+
services.AddDbContextUsePostgres<MyDbContext>(connectionString, 3);
34+
}
35+
```
36+
37+
<b>Note:</b>The value <b>3</b> indicates the number of attempts (retryOnFailure), in order to avoid transient errors.
38+
39+
If you don't want to activate connection resiliency, set the value to <b>zero</b>.
40+
41+
Finally you need to replace the <b>MyDbContext</b> value with the actual implementation of your DbContext

0 commit comments

Comments
 (0)