Skip to main content
.NETFramework4.6.2net8.0net9.0net10.0

Asynchronous feature store.

Published
Sep 9, 2026
1mo ago
Total Downloads
116.8K
116,842

Install

dotnet add package Microsoft.Extensions.AsyncState --version 10.10.0
ProductVersions
.NET
net10.0net8.0net9.0
Other
.NETFramework4.6.2

README

Microsoft.Extensions.AsyncState

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> 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.

Please note, the implementations of IAsyncState and IAsyncContext<T> are not thread-safe.

Install the package

From the command-line:

dotnet add package Microsoft.Extensions.AsyncState

Or directly in the C# project file:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.AsyncState" Version="[CURRENTVERSION]" />
</ItemGroup>

Usage Example

Registering Services

The services can be registered using the following method:

public static IServiceCollection AddAsyncState(this IServiceCollection services)

Consuming Services

The IAsyncContext<T> can be injected wherever async state is needed. For example:

public class MyClass
{
  public MyClass(IAsyncContext<MyState> asyncContext) { Context = asyncContext }

  private IAsyncContext<MyState> Context { get; }

  public async Task DoWork()
  {
    var state = Context.Get();
    // or
    Context.Set(new MyState());
    // or
    if (Context.TryGet(out var state)) { ... }
  }
}

Feedback & Contributing

We welcome feedback and contributions in our GitHub repo.

Changes from Previous Version

No structural changes between v10.9.0 and v10.10.0.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.