Skip to content

Commit 29116a1

Browse files
committed
Delete bad AppDb example from documentation.
It doesn't add any useful functionality, and might encourage people to use it (incorrectly) as a singleton.
1 parent a291580 commit 29116a1

File tree

1 file changed

+2
-49
lines changed

1 file changed

+2
-49
lines changed
Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lastmod: 2016-10-16
2+
lastmod: 2021-09-21
33
date: 2016-10-16
44
menu:
55
main:
@@ -17,51 +17,4 @@ To connect to a database on `localhost` port `3306` with a user `mysqltest`, pas
1717

1818
`host=127.0.0.1;port=3306;user id=mysqltest;password=Password123;database=mysqldb;`
1919

20-
For all connection string options, view the [Connection Options Reference](/connection-options/)
21-
22-
### Application Database Object Example
23-
24-
It's a good idea to use an IDisposable object that configures the connection string globally, and closes the connection automatically:
25-
26-
```csharp
27-
public class AppDb : IDisposable
28-
{
29-
public readonly MySqlConnection Connection;
30-
31-
public AppDb()
32-
{
33-
Connection = new MySqlConnection("host=127.0.0.1;port=3306;user id=mysqltest;password=Password123;database=mysqldb;");
34-
}
35-
36-
public void Dispose()
37-
{
38-
Connection.Close();
39-
}
40-
}
41-
42-
```
43-
44-
Callers can use the Application Database Object object like so:
45-
46-
```csharp
47-
public async Task AsyncMethod()
48-
{
49-
using (var db = new AppDb())
50-
{
51-
await db.Connection.OpenAsync();
52-
// db.Connection is open and ready to use
53-
}
54-
// db.Connection was closed by AppDb.Dispose
55-
}
56-
57-
public void SyncMethod()
58-
{
59-
using (var db = new AppDb())
60-
{
61-
db.Connection.Open();
62-
// db.Connection is open and ready to use
63-
}
64-
// db.Connection was closed by AppDb.Dispose
65-
}
66-
67-
```
20+
For all connection string options, view the [Connection Options Reference](/connection-options/).

0 commit comments

Comments
 (0)