Class CosmosTenantItemRepository<T>
Provides repository implementation for items that belong to a tenant.
Inheritance
Inherited Members
Namespace: Benday.CosmosDb.Repositories
Assembly: Benday.CosmosDb.dll
Syntax
public class CosmosTenantItemRepository<T> : CosmosRepository<T>, ITenantItemRepository<T>, IRepository<T>, IAsyncTenantRepository<T, string>, IAsyncRepository<T, string> where T : class, ITenantItem, new()
Type Parameters
| Name | Description |
|---|---|
| T | Domain model type managed by the repository |
Constructors
| Edit this page View SourceCosmosTenantItemRepository(IOptions<CosmosRepositoryOptions<T>>, CosmosClient, ILogger<CosmosTenantItemRepository<T>>, ICosmosQueryLogSink?)
Provides repository implementation for items that belong to a tenant.
Declaration
public CosmosTenantItemRepository(IOptions<CosmosRepositoryOptions<T>> options, CosmosClient client, ILogger<CosmosTenantItemRepository<T>> logger, ICosmosQueryLogSink? sink = null)
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<CosmosTenantItemRepository<T>> | logger | |
| ICosmosQueryLogSink | sink |
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 SourceDeleteAllByTenantIdAsync(string, int, int, CancellationToken)
Deletes all items for the specified tenant with configurable throttling and retry logic.
Declaration
public Task DeleteAllByTenantIdAsync(string tenantId, int maxConcurrency, int maxRetries, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tenantId | Tenant 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 |
DeleteAllByTenantIdAsync(string, CancellationToken)
Deletes all items for the specified tenant with throttling and retry logic.
Declaration
public Task DeleteAllByTenantIdAsync(string tenantId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tenantId | Tenant 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 tenant id. Default implementation will return items in descending order by timestamp.
Declaration
public Task<IEnumerable<T>> GetAllAsync(string tenantId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tenantId | Tenant id |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<T>> |
GetByIdAsync(string, string)
Gets an entity by its id and tenant id.
Declaration
public virtual Task<T?> GetByIdAsync(string tenantId, string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tenantId | |
| string | id |
Returns
| Type | Description |
|---|---|
| Task<T> | Matching item or null if not found |
GetPagedAsync(string, int, string?)
Gets a page of results for the specified tenant with continuation support.
Declaration
public Task<PagedResults<T>> GetPagedAsync(string tenantId, int pageSize = 100, string? continuationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tenantId | Tenant id |
| int | pageSize | Maximum number of items to return |
| string | continuationToken | Continuation token from previous query (null for first page) |
Returns
| Type | Description |
|---|---|
| Task<PagedResults<T>> | A page of results with continuation information |
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 |