Skip to content

Commit

Permalink
Improve AsyncState README (#4764)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
  • Loading branch information
sebastienros and RussKie authored Nov 29, 2023
1 parent c838390 commit 13a6288
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Libraries/Microsoft.AspNetCore.AsyncState/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Microsoft.AspNetCore.AsyncState

This provides the ability to store and retrieve state objects that flow with the current `HttpContext` across asynchronous operations. See `Microsoft.Extensions.AsyncState` for additional information.
This provides the ability to store and retrieve state objects that flow with the current `HttpContext` across asynchronous operations. See [Microsoft.Extensions.AsyncState](../Microsoft.Extensions.AsyncState/README.md) for additional information.

The lifetime of the shared data is controlled automatically and will be the same as of `HttpContext`.

## Install the package

Expand Down Expand Up @@ -28,6 +30,8 @@ The services can be registered using the following method:
public static IServiceCollection AddAsyncStateHttpContext(this IServiceCollection services)
```

Note: When calling `AddAsyncStateHttpContext()` there is no need to also invoke `AddAsyncState()` from the `Microsoft.Extensions.AsyncState` package.

### Consuming Services

The `IAsyncContext<T>` can be injected wherever async state is needed. For example:
Expand Down
7 changes: 6 additions & 1 deletion src/Libraries/Microsoft.Extensions.AsyncState/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Microsoft.Extensions.AsyncState

This provides the ability to store and retrieve state objects that flow with the current asynchronous context.
This provides the ability to store and retrieve objects that flow with the current asynchronous context.

It has a few advantages over using the [`AsyncLocal<T>`](https://learn.microsoft.com/dotnet/api/system.threading.asynclocal-1) class directly:
- By abstracting the way the ambient data is stored we can use more optimized implementations, for instance when using ASP.NET Core, without exposing these components.
- Improves the performance by minimizing the number of `AsyncLocal<T>` instances required when multiple objects are shared.
- Provides a way to manage the lifetime of the ambient data objects.

## Install the package

Expand Down

0 comments on commit 13a6288

Please sign in to comment.