A core library providing the foundational building blocks for asynchronous key-value operations.
These are the foundational interfaces for asynchronous access to entities and resources:
IReadAsync<TKey, TValue>- Fundamental read operations (exists, read)ICreateAsync<TKey, TValue>- Interface for creating new entriesIUpdateAsync<TKey, TValue>- Interface for updating existing entriesIDeleteAsync<TKey>- Interface for deleting entriesICreateOrUpdate<TKey, TValue>- Combined interface for inserting or updating entries
These interfaces allow for fine-grained control over dependencies, making your code more focused and testable.
These interfaces build upon the foundation blocks to provide more comprehensive functionality:
IAsyncDictionary<TKey, TValue>- Full-featured async dictionary interface combining read, create, update, and delete operationsISynchronizedAsyncDictionary<TKey, TValue>- Provides synchronized, exclusive leased access to dictionary entries to prevent concurrency conflicts
Ready-to-use implementations built from the foundational components:
MemoryAsyncDictionary<TKey, TValue>- In-memory implementation of async dictionarySynchronizedAsyncDictionary<TKey, TValue>- Synchronized wrapper for any async dictionary
// Only depend on the operations you actually need
public class UserProfileService
{
private readonly IReadAsync<string, UserProfile> _profileReader;
private readonly IUpdateAsync<string, UserProfile> _profileUpdater;
public UserProfileService(
IReadAsync<string, UserProfile> profileReader,
IUpdateAsync<string, UserProfile> profileUpdater)
{
_profileReader = profileReader;
_profileUpdater = profileUpdater;
}
public async Task<UserProfile> GetUserProfileAsync(string userId)
=> await _profileReader.ReadAsync(userId);
public async Task UpdateUserEmailAsync(string userId, string newEmail)
{
var profile = await _profileReader.ReadAsync(userId);
profile.Email = newEmail;
await _profileUpdater.UpdateAsync(userId, profile);
}
}- Interface segregation principles for precise dependency injection
- Async-first design with ValueTask support for high performance
- Thread-safe implementations for concurrent scenarios
- Comprehensive test coverage for reliability
This project is licensed under the MIT License - see the LICENSE file for details.