This repository was archived by the owner on Apr 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
src/NET6CustomLibrary/Docs Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments