A flexible storage abstraction that provides partitioned data storage capabilities with multiple backend implementations including in-memory, file system, and DynamoDB.
The main entry point for accessing storage partitions.
public interface Partitions
{
Partition<TData> Get<TData>(string partitionName)
where TData : new();
}
Represents a single partition that can store items of type TData
.
public interface Partition<TData>
where TData : new()
{
Task<Item<TData>> Get(string id);
Task<string> Save(Item<TData> item);
Task<Item<TData>[]> Scan(ScanOptions options);
Task Remove(string id);
}
- Get: Retrieve a single item by ID
- Save: Create or update an item
- Scan: Query multiple items with filtering options
- Remove: Delete an item
-
Memory Storage (
MemoryPartitions
)- In-memory storage suitable for testing and temporary data
- No persistence between application restarts
-
File Storage (
FilePartitions
)- Persists data to the file system
- Requires configuration via
FilePartitionedStorageOptions
-
DynamoDB Storage (
DynamoDBPartitions
)- Amazon DynamoDB backend implementation
- Requires AWS credentials and region configuration
- Configurable table name prefix
Required environment variables:
PartitionedStorageAccessKeyId
: AWS access key IDPartitionedStorageSecretAccessKey
: AWS secret access keyPartitionedStorageRegion
: AWS region name
// Memory Storage
services.AddSingleton<Partitions, MemoryPartitions>()
.AddSingleton<ItemSerializer, JsonItemSerializer>();
// File Storage
services.AddSingleton<Partitions, FilePartitions>()
.AddSingleton<ItemSerializer, JsonItemSerializer>()
.AddSingleton<FilePartitionedStorageOptions, CustomOptions>();
// DynamoDB Storage
services.AddSingleton<Partitions, DynamoDBPartitions>()
.AddSingleton<ItemSerializer, JsonItemSerializer>()
.AddSingleton(new DynamoDBPartitionedStorageOptions()
{
TableNamePrefix = "YourPrefix"
});
The implementation throws several specific exceptions:
PartitionedStorageItemNotFoundException
: Item or partition not foundPartitionedStorageItemAlreadyExistsException
: Attempted to create a duplicate itemPartitionedStorageItemVersionMismatchException
: Concurrent modification detected
The ScanOptions
class provides various filtering capabilities:
MaxItems
: Limit the number of returned itemsFromItem
: Start scanning from this item IDToItem
: Stop scanning at this item IDOrder
: Specify scan direction (Ascending/Descending)
Example:
var options = new ScanOptions
{
MaxItems = 10,
FromItem = "A",
ToItem = "Z",
Order = ScanOrder.Ascending
};
Items support optimistic concurrency control through versioning:
- Each save operation returns a version string
- Updates must include the current version
- Concurrent modifications are detected and prevented