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

Commit 05cdfce

Browse files
committed
Aggiornata documentazione
1 parent 5ac38e6 commit 05cdfce

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Documentation is available by clicking [here](https://github.com/AngeloDotNet/NE
3838
Documentation is available by clicking [here](https://github.com/AngeloDotNet/NET6CustomLibrary/blob/main/src/NET6CustomLibrary/Docs/README-Json.md)
3939

4040

41+
### DBContext Pool MySQL / MariaDB
42+
43+
Documentation is available by clicking [here](https://github.com/AngeloDotNet/NET6CustomLibrary/blob/main/src/NET6CustomLibrary/Docs/README-DbContextPool-MySQL.md)
44+
45+
46+
### Health Checks MySQL / MariaDB
47+
48+
Documentation is available by clicking [here](https://github.com/AngeloDotNet/NET6CustomLibrary/blob/main/src/NET6CustomLibrary/Docs/README-HealthChecks-MySQL.md)
49+
50+
4151
### Contributing
4252

4353
Contributions and/or suggestions are always welcome.
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 MySQL database
2+
3+
4+
## Configuration to add to the appsettings.json file
5+
6+
```json
7+
"ConnectionStrings": {
8+
"Default": "Server=[SERVER];Database=[DATABASE];Uid=[USERNAME];Pwd=[PASSWORD];Port=3306"
9+
},
10+
```
11+
12+
<b>Note:</b> The default port for Mysql / MariaDB is 3306, 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.AddDbContextUseMySql<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
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Health Checks configuration for MySQL database
2+
3+
4+
## Configuration to add to the appsettings.json file
5+
6+
```json
7+
"ConnectionStrings": {
8+
"Default": "Server=[SERVER];Database=[DATABASE];Uid=[USERNAME];Pwd=[PASSWORD];Port=3306"
9+
},
10+
```
11+
12+
<b>Note:</b> The default port for Mysql / MariaDB is 3306, 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+
var connectionString = Configuration.GetSection("ConnectionStrings").GetValue<string>("Default");
28+
services.AddMySqlHealthChecks(connectionString, "MySQL");
29+
}
30+
31+
//OMISSIS
32+
33+
public void Configure(WebApplication app)
34+
{
35+
//OMISSIS
36+
37+
app.UseEndpoints(endpoints =>
38+
{
39+
endpoints.MapControllers();
40+
endpoints.AddDatabaseHealthChecks("/status");
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)