Show / Hide Table of Contents

Class CosmosTenantItemRepository<T>

Provides repository implementation for items that belong to a tenant.

Inheritance
object
CosmosRepository<T>
CosmosTenantItemRepository<T>
CosmosDbParentedItemRepository<T>
Implements
ITenantItemRepository<T>
IRepository<T>
IAsyncTenantRepository<T, string>
IAsyncRepository<T, string>
Inherited Members
CosmosRepository<T>.EntityType
CosmosRepository<T>.Logger
CosmosRepository<T>._Options
CosmosRepository<T>._sink
CosmosRepository<T>.GetContainerAsync()
CosmosRepository<T>.DeleteAsync(string)
CosmosRepository<T>.GetAllAsync()
CosmosRepository<T>.GetResultsAsync<TResult>(IQueryable<TResult>, string, PartitionKey)
CosmosRepository<T>.GetResultsAsync<TResult>(QueryDefinition, string, PartitionKey)
CosmosRepository<T>.GetResultsAsync(QueryDefinition, string, PartitionKey)
CosmosRepository<T>.GetResultsAsync<TResult>(FeedIterator<TResult>, string, string, IReadOnlyDictionary<string, object>, PartitionKey)
CosmosRepository<T>.GetQueryDescription(string)
CosmosRepository<T>.GetQueryDescription(string, string)
CosmosRepository<T>.IsCrossPartitionQuery(CosmosDiagnostics)
CosmosRepository<T>.LogPointOperationDiagnostics(string, double, CosmosDiagnostics, TimeSpan)
CosmosRepository<T>.LogFeedResponseDiagnostics(string, double, CosmosDiagnostics, TimeSpan, int, string, IReadOnlyDictionary<string, object>, PartitionKey)
CosmosRepository<T>.LogQueryTotalDiagnostics(string, double, TimeSpan, int, string, IReadOnlyDictionary<string, object>, PartitionKey, bool)
CosmosRepository<T>.OnQueryDiagnostics(CosmosQueryDiagnostics)
CosmosRepository<T>.ExecuteScalarAsync<TResult>(IQueryable<T>, Func<IQueryable<T>, Task<Response<TResult>>>, string, PartitionKey, Func<TResult, int>)
CosmosRepository<T>.GetByIdAsync(string)
CosmosRepository<T>.Initialize()
CosmosRepository<T>.SaveAsync(T)
CosmosRepository<T>.BatchSize
CosmosRepository<T>.SaveAsync(IList<T>)
CosmosRepository<T>.SaveBatchAsync(int, int, T[])
CosmosRepository<T>.AfterSaveBatch(TransactionalBatchResponse, T[], int, int)
CosmosRepository<T>.BeforeSaveBatch(TransactionalBatch, T[], int, int)
CosmosRepository<T>.GetPartitionKey(T)
CosmosRepository<T>.GetPartitionKey(string, string)
CosmosRepository<T>.GetQueryContextAsync(string)
CosmosRepository<T>.GetQueryContextAsync(string, string)
CosmosRepository<T>.GetQueryContextAsync()
CosmosRepository<T>.GetPagedAsync(int, string)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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 Source

CosmosTenantItemRepository(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 Source

BulkMaxConcurrency

Maximum concurrent operations for bulk operations. Override in derived class if needed.

Declaration
protected virtual int BulkMaxConcurrency { get; }
Property Value
Type Description
int
| Edit this page View Source

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 Source

DeleteAllByTenantIdAsync(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
| Edit this page View Source

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
| Edit this page View Source

DeleteAsync(T)

Delete an item from the repository.

Declaration
public Task DeleteAsync(T itemToDelete)
Parameters
Type Name Description
T itemToDelete
Returns
Type Description
Task
| Edit this page View Source

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
| Edit this page View Source

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>>
| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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

Implements

ITenantItemRepository<T>
IRepository<T>
Benday.Common.Interfaces.IAsyncTenantRepository<T, TKey>
Benday.Common.Interfaces.IAsyncRepository<T, TKey>
  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com