Skip to content

Commit ccd2fe1

Browse files
committed
Update package readme for DI and logging. Fixes #1280
1 parent 1d3557c commit ccd2fe1

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/MySqlConnector.DependencyInjection/docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ For example, if using the ASP.NET minimal web API, use the following to register
1111
```csharp
1212
var builder = WebApplication.CreateBuilder(args);
1313

14-
builder.Services.AddMySqlDataSource("Server=server;User ID=test;Password=test;Database=test");
14+
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Default"));
1515
```
1616

1717
This registers a transient `MySqlConnection` which can get injected into your controllers:
@@ -21,7 +21,7 @@ app.MapGet("/", async (MySqlConnection connection) =>
2121
{
2222
await connection.OpenAsync();
2323
await using var command = connection.CreateCommand();
24-
command.CommandText = "SELECT name FROM users LIMIT 1";
24+
command.CommandText = "SELECT name FROM users LIMIT 1";
2525
return "Hello World: " + await command.ExecuteScalarAsync();
2626
});
2727
```

src/MySqlConnector/docs/README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ while (reader.Read())
3535
}
3636
```
3737

38+
### ASP.NET
39+
40+
For ASP.NET, use the [MySqlConnector.DependencyInjection package](https://www.nuget.org/packages/MySqlConnector.DependencyInjection/) to integrate with dependency injection and logging.
41+
42+
```csharp
43+
var builder = WebApplication.CreateBuilder(args);
44+
45+
// use AddMySqlDataSource to configure MySqlConnector
46+
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Default"));
47+
48+
var app = builder.Build();
49+
50+
// use dependency injection to get a MySqlConnection in minimal APIs or in controllers
51+
app.MapGet("/", async (MySqlConnection connection) =>
52+
{
53+
// open and use the connection here
54+
await connection.OpenAsync();
55+
await using var command = connection.CreateCommand();
56+
command.CommandText = "SELECT name FROM users LIMIT 1";
57+
return "Hello World: " + await command.ExecuteScalarAsync();
58+
});
59+
60+
app.Run();
61+
```
62+
3863
## Key Features
3964

4065
* Full support for async I/O
@@ -58,8 +83,8 @@ The main types provided by this library are:
5883

5984
## Related Packages
6085

86+
* Dependency Injection: [MySqlConnector.DependencyInjection](https://www.nuget.org/packages/MySqlConnector.DependencyInjection/)
6187
* Entity Framework Core: [Pomelo.EntityFrameworkCore.MySql](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/)
62-
* Logging: [log4net](https://www.nuget.org/packages/MySqlConnector.Logging.log4net/), [Microsoft.Extensions.Logging](https://www.nuget.org/packages/MySqlConnector.Logging.Microsoft.Extensions.Logging/), [NLog](https://www.nuget.org/packages/MySqlConnector.Logging.NLog/), [Serilog](https://www.nuget.org/packages/MySqlConnector.Logging.Serilog/)
6388

6489
## Feedback
6590

0 commit comments

Comments
 (0)