Skip to content

Commit ad01750

Browse files
committed
Fixed README.md
1 parent f2897ae commit ad01750

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The `DatabaseContextService` provides ambient access to the current `IDatabaseCo
6767

6868
``` c#
6969
event EventHandler<DatabaseContextAsyncLocalValueChangedEventArgs> DatabaseContextAsyncLocalValueChanged;
70+
7071
event EventHandler<DatabaseContextAsyncLocalValueAssignedEventArgs> DatabaseContextAsyncLocalValueAssigned;
7172
```
7273

@@ -76,19 +77,19 @@ Attach delegates to the above events should you wish to track ambient data chang
7677
void BeginScope()
7778
```
7879

79-
Before any database context can be created a scope must be started. This is typically done in the integration/application layer (controller/minimal API methods, message handlers). Nested scopes are not permitted as the ambient context will flow across any `async` methods.
80-
81-
``` c#
82-
8380
# IDatabaseContextFactory
8481

8582
In order to access a database we need a database connection. A database connection is represented by an `IDatabaseContext` instance that may be obtained by using an instance of an `IDatabaseContextFactory` implementation.
8683

8784
The `DatabaseContextFactory` implementation makes use of an `IDbConnectionFactory` implementation which creates a `System.Data.IDbConnection` by using the provider name and connection string, which is obtained from the registered connection name. An `IDbCommandFactory` creates a `System.Data.IDbCommand` by using an `IDbConnection` instance.
8885

86+
Before any database context can be created a scope must be started. This is typically done in the integration/application layer (controller/minimal API methods, message handlers). Nested scopes are not permitted as the ambient context will flow across any `async` methods.
87+
8988
``` c#
89+
var databaseContextService = provider.GetRequiredService<IDatabaseContextService>();
9090
var databaseContextFactory = provider.GetRequiredService<IDatabaseContextFactory>();
9191

92+
using (databaseContextService.BeginScope()) // <-- will configure the scope (cannot be nested)
9293
using (var databaseContext = databaseContextFactory.Create("connection-name"))
9394
{
9495
// database interaction

0 commit comments

Comments
 (0)