Class CosmosOwnedItemRepository<T>
Provides repository implementation for items that are owned by a user.
Inheritance
Inherited Members
Namespace: Benday.CosmosDb.Repositories
Assembly: Benday.CosmosDb.dll
Syntax
public class CosmosOwnedItemRepository<T> : CosmosRepository<T>, IOwnedItemRepository<T>, IRepository<T> where T : class, IOwnedItem, new()
Type Parameters
| Name | Description |
|---|---|
| T | Domain model type managed by the repository |
Constructors
| Edit this page View SourceCosmosOwnedItemRepository(IOptions<CosmosRepositoryOptions<T>>, CosmosClient, ILogger<CosmosOwnedItemRepository<T>>)
Provides repository implementation for items that are owned by a user.
Declaration
public CosmosOwnedItemRepository(IOptions<CosmosRepositoryOptions<T>> options, CosmosClient client, ILogger<CosmosOwnedItemRepository<T>> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IOptions<CosmosRepositoryOptions<T>> | options | Configuration options for the repository |
| CosmosClient | client | Instance of the cosmos db client. NOTE: for performance reasons, this should probably be a singleton in the application. |
| ILogger<CosmosOwnedItemRepository<T>> | logger |
Properties
| Edit this page View SourceBulkMaxConcurrency
Maximum concurrent operations for bulk operations. Override in derived class if needed.
Declaration
protected virtual int BulkMaxConcurrency { get; }
Property Value
| Type | Description |
|---|---|
| int |
BulkMaxRetries
Maximum retry attempts for throttled requests. Override in derived class if needed.
Declaration
protected virtual int BulkMaxRetries { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceDeleteAllByOwnerIdAsync(string, int, int, CancellationToken)
Deletes all items for the specified owner with configurable throttling and retry logic.
Declaration
public Task DeleteAllByOwnerIdAsync(string ownerId, int maxConcurrency, int maxRetries, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | ownerId | Owner id for the items to delete |
| int | maxConcurrency | Maximum number of concurrent delete operations |
| int | maxRetries | Maximum number of retry attempts for throttled requests |
| CancellationToken | cancellationToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
DeleteAllByOwnerIdAsync(string, CancellationToken)
Deletes all items for the specified owner with throttling and retry logic.
Declaration
public Task DeleteAllByOwnerIdAsync(string ownerId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | ownerId | Owner id for the items to delete |
| CancellationToken | cancellationToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
DeleteAsync(T)
Delete an item from the repository.
Declaration
public Task DeleteAsync(T itemToDelete)
Parameters
| Type | Name | Description |
|---|---|---|
| T | itemToDelete |
Returns
| Type | Description |
|---|---|
| Task |
DeleteWithRetryAsync(T, int, CancellationToken)
Deletes a single item with retry logic for throttled requests (HTTP 429).
Declaration
protected Task DeleteWithRetryAsync(T item, int maxRetries, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to delete |
| int | maxRetries | Maximum number of retry attempts |
| CancellationToken | cancellationToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
GetAllAsync(string)
Get all items in the repository that have the specified owner id. Default implementation will return items in descending order by timestamp.
Declaration
public Task<IEnumerable<T>> GetAllAsync(string ownerId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | ownerId | Owner id |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<T>> |
GetByIdAsync(string, string)
Gets an entity by its id and owner id.
Declaration
public virtual Task<T?> GetByIdAsync(string ownerId, string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | ownerId | |
| string | id |
Returns
| Type | Description |
|---|---|
| Task<T> | Matching item or null if not found |
SaveAllAsync(IEnumerable<T>, int, int, CancellationToken)
Saves multiple items with configurable throttling and retry logic.
Declaration
public Task SaveAllAsync(IEnumerable<T> items, int maxConcurrency, int maxRetries, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | Items to save |
| int | maxConcurrency | Maximum number of concurrent save operations |
| int | maxRetries | Maximum number of retry attempts for throttled requests |
| CancellationToken | cancellationToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
SaveAllAsync(IEnumerable<T>, CancellationToken)
Saves multiple items with throttling and retry logic.
Declaration
public Task SaveAllAsync(IEnumerable<T> items, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | Items to save |
| CancellationToken | cancellationToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
SaveWithRetryAsync(T, int, CancellationToken)
Saves a single item with retry logic for throttled requests (HTTP 429).
Declaration
protected Task SaveWithRetryAsync(T item, int maxRetries, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to save |
| int | maxRetries | Maximum number of retry attempts |
| CancellationToken | cancellationToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |