Class Repository
Base repository class for interacting with AWS DynamoDB tables.
Inherited Members
Namespace: Innovt.Cloud.AWS.Dynamo
Assembly: Innovt.Cloud.AWS.Dynamo.dll
Syntax
public abstract class Repository : AwsBaseService, ITableRepository, IDisposable
Constructors
| Edit this page View SourceRepository(ILogger, IAwsConfiguration)
Initializes a new instance of the Repository class.
Declaration
protected Repository(ILogger logger, IAwsConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The logger. |
IAwsConfiguration | configuration | AWS configuration. |
Repository(ILogger, IAwsConfiguration, DynamoContext)
Initializes a new instance of the Repository class using a context map.
Declaration
protected Repository(ILogger logger, IAwsConfiguration configuration, DynamoContext context)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | |
IAwsConfiguration | configuration | |
DynamoContext | context |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
Repository(ILogger, IAwsConfiguration, string)
Initializes a new instance of the Repository class.
Declaration
protected Repository(ILogger logger, IAwsConfiguration configuration, string region)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The logger. |
IAwsConfiguration | configuration | AWS configuration. |
string | region | The AWS region. |
Methods
| Edit this page View SourceAddAsync<T>(T, CancellationToken)
Asynchronously adds a single item to the repository.
Declaration
public Task AddAsync<T>(T message, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | message | The item to add. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous add operation. |
Type Parameters
Name | Description |
---|---|
T | The type of item to add. |
AddRangeAsync<T>(ICollection<T>, CancellationToken)
Adds a list of items to the DynamoDB table.
Declaration
public Task AddRangeAsync<T>(ICollection<T> messages, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | messages | The list of items to add. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task |
Type Parameters
Name | Description |
---|---|
T | The type of items to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the messages parameter is null. |
BatchGetItem<T>(BatchGetItemRequest, CancellationToken)
Gets a batch of items from the DynamoDB table based on the specified batch get item request.
Declaration
public Task<List<T>> BatchGetItem<T>(BatchGetItemRequest batchGetItemRequest, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
BatchGetItemRequest | batchGetItemRequest | The batch get item request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<List<T>> | The list of items retrieved. |
Type Parameters
Name | Description |
---|---|
T | The type of items to get. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the batch get item request is null. |
BatchWriteItem(BatchWriteItemRequest, CancellationToken)
Writes a batch of items to the DynamoDB table based on the specified batch write item request.
Declaration
public Task<BatchWriteItemResponse> BatchWriteItem(BatchWriteItemRequest batchWriteItemRequest, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
BatchWriteItemRequest | batchWriteItemRequest | The batch write item request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<BatchWriteItemResponse> | The response indicating the result of the batch write operation. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the batch write item request is null. |
CreateDefaultRetryAsyncPolicy()
Creates the default asynchronous retry policy for handling exceptions during operations.
Declaration
protected override AsyncRetryPolicy CreateDefaultRetryAsyncPolicy()
Returns
Type | Description |
---|---|
AsyncRetryPolicy | The asynchronous retry policy instance. |
Overrides
| Edit this page View SourceCreateTransactionWriteItem<T>(T, TransactionWriteOperationType)
Create a transaction write item based on the instance.
Declaration
public TransactionWriteItem CreateTransactionWriteItem<T>(T instance, TransactionWriteOperationType operationType = TransactionWriteOperationType.Put) where T : class, new()
Parameters
Type | Name | Description |
---|---|---|
T | instance | A mapped instance with context. |
TransactionWriteOperationType | operationType | The operation that you want to perform. |
Returns
Type | Description |
---|---|
TransactionWriteItem | A incomplete transaction write item with properties mapped. |
Type Parameters
Name | Description |
---|---|
T | A typed mapped entity |
DeleteAsync<T>(object, string, CancellationToken)
Asynchronously deletes an item using its identifier and optional range key.
Declaration
public Task DeleteAsync<T>(object id, string rangeKey = null, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
object | id | The identifier of the item. |
string | rangeKey | The range key for the item (optional). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous delete operation. |
Type Parameters
Name | Description |
---|---|
T | The type of item to delete. |
DeleteAsync<T>(T, CancellationToken)
Asynchronously deletes an item using its value.
Declaration
public Task DeleteAsync<T>(T message, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | message | The item to delete. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous delete operation. |
Type Parameters
Name | Description |
---|---|
T | The type of item to delete. |
DeleteRangeAsync<T>(ICollection<T>, CancellationToken)
Asynchronously a list of item that are from the same type.
Declaration
public Task DeleteRangeAsync<T>(ICollection<T> messages, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | messages | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
Type Parameters
Name | Description |
---|---|
T |
DisposeServices()
Disposes the DynamoDB context and AmazonDynamoDBClient resources.
Declaration
protected override void DisposeServices()
Overrides
| Edit this page View SourceExecuteStatementAsync<T>(ExecuteSqlStatementRequest, CancellationToken)
Executes a SQL statement asynchronously and returns the response containing items of type T.
Declaration
public Task<ExecuteSqlStatementResponse<T>> ExecuteStatementAsync<T>(ExecuteSqlStatementRequest sqlStatementRequest, CancellationToken cancellationToken = default) where T : class, new()
Parameters
Type | Name | Description |
---|---|---|
ExecuteSqlStatementRequest | sqlStatementRequest | The SQL statement request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<ExecuteSqlStatementResponse<T>> | The response containing items of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of items to be returned. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the SQL statement request is null. |
GetByIdAsync<T>(object, string?, CancellationToken)
Asynchronously retrieves an item by its identifier.
Declaration
public Task<T?> GetByIdAsync<T>(object id, string? rangeKey = null, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
object | id | The identifier of the item. |
string | rangeKey | The range key for the item (optional). |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<T> | An item of type T if found; otherwise, null. |
Type Parameters
Name | Description |
---|---|
T | The type of item to retrieve. |
QueryAsync<T>(QueryRequest, CancellationToken)
Queries the DynamoDB table using a query request and returns a list of items.
Declaration
public Task<IList<T>> QueryAsync<T>(QueryRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<IList<T>> | A list of items based on the query request. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
QueryAsync<T>(object, CancellationToken)
Queries the DynamoDB table and returns a list of items with the specified id.
Declaration
public Task<IList<T>> QueryAsync<T>(object id, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
object | id | The id to query. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<IList<T>> | A list of items with the specified id. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
QueryFirstAsync<T>(object, CancellationToken)
Asynchronously queries and retrieves the first item of type T by its identifier.
Declaration
public Task<T?> QueryFirstAsync<T>(object id, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
object | id | The identifier of the item. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<T> | An item of type T if found; otherwise, null. |
Type Parameters
Name | Description |
---|---|
T | The type of item to retrieve. |
QueryFirstOrDefaultAsync<T>(QueryRequest, CancellationToken)
Queries the DynamoDB table and returns the first or default item based on the query request.
Declaration
public Task<T?> QueryFirstOrDefaultAsync<T>(QueryRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<T> | The first or default item based on the query request. |
Type Parameters
Name | Description |
---|---|
T | The type of item to query. |
QueryMultipleAsync<T, TResult1, TResult2>(QueryRequest, string, CancellationToken)
Queries the DynamoDB table using a query request and splits the results into two types based on a key.
Declaration
public Task<(IList<TResult1> first, IList<TResult2> second)> QueryMultipleAsync<T, TResult1, TResult2>(QueryRequest request, string splitBy, CancellationToken cancellationToken = default) where T : class where TResult1 : class where TResult2 : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
string | splitBy | The key to split the results. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<(IList<TResult1> first, IList<TResult2> second)> | Tuple containing lists of items split based on the specified key. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
TResult1 | The first type to split the results into. |
TResult2 | The second type to split the results into. |
QueryMultipleAsync<T, TResult1, TResult2, TResult3>(QueryRequest, string[], CancellationToken)
Queries the DynamoDB table using a query request and splits the results into three types based on specified keys.
Declaration
public Task<(IList<TResult1> first, IList<TResult2> second, IList<TResult3> third)> QueryMultipleAsync<T, TResult1, TResult2, TResult3>(QueryRequest request, string[] splitBy, CancellationToken cancellationToken = default) where T : class where TResult1 : class where TResult2 : class where TResult3 : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
string[] | splitBy | The keys to split the results. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<(IList<TResult1> first, IList<TResult2> second, IList<TResult3> third)> | Tuple containing lists of items split based on the specified keys. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
TResult1 | The first type to split the results into. |
TResult2 | The second type to split the results into. |
TResult3 | The third type to split the results into. |
QueryMultipleAsync<T, TResult1, TResult2, TResult3, TResult4>(QueryRequest, string[], CancellationToken)
Queries the DynamoDB table using a query request and splits the results into four types based on specified keys.
Declaration
public Task<(IList<TResult1> first, IList<TResult2> second, IList<TResult3> third, IList<TResult4> fourth)> QueryMultipleAsync<T, TResult1, TResult2, TResult3, TResult4>(QueryRequest request, string[] splitBy, CancellationToken cancellationToken = default) where T : class where TResult1 : class where TResult2 : class where TResult3 : class where TResult4 : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
string[] | splitBy | The keys to split the results. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<(IList<TResult1> first, IList<TResult2> second, IList<TResult3> third, IList<TResult4> fourth)> | Tuple containing lists of items split based on the specified keys. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
TResult1 | The first type to split the results into. |
TResult2 | The second type to split the results into. |
TResult3 | The third type to split the results into. |
TResult4 | The fourth type to split the results into. |
QueryMultipleAsync<T, TResult1, TResult2, TResult3, TResult4, TResult5>(QueryRequest, string[], CancellationToken)
Queries the DynamoDB table using a query request and splits the results into five types based on specified keys.
Declaration
public Task<(IList<TResult1> first, IList<TResult2> second, IList<TResult3> third, IList<TResult4> fourth, IList<TResult5> fifth)> QueryMultipleAsync<T, TResult1, TResult2, TResult3, TResult4, TResult5>(QueryRequest request, string[] splitBy, CancellationToken cancellationToken = default) where T : class where TResult1 : class where TResult2 : class where TResult3 : class where TResult4 : class where TResult5 : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
string[] | splitBy | The keys to split the results. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<(IList<TResult1> first, IList<TResult2> second, IList<TResult3> third, IList<TResult4> fourth, IList<TResult5> fifth)> | Tuple containing lists of items split based on the specified keys. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
TResult1 | The first type to split the results into. |
TResult2 | The second type to split the results into. |
TResult3 | The third type to split the results into. |
TResult4 | The fourth type to split the results into. |
TResult5 | The fifth type to split the results into. |
QueryPaginatedByAsync<T>(QueryRequest, CancellationToken)
Queries the DynamoDB table using a query request and returns a paginated collection of items.
Declaration
public Task<PagedCollection<T>> QueryPaginatedByAsync<T>(QueryRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
QueryRequest | request | The query request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<PagedCollection<T>> | A paginated collection of items based on the query request. |
Type Parameters
Name | Description |
---|---|
T | The type of items to query. |
ScanAsync<T>(ScanRequest, CancellationToken)
Scans the DynamoDB table based on the specified scan request.
Declaration
public Task<IList<T>> ScanAsync<T>(ScanRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
ScanRequest | request | The scan request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<IList<T>> | The list of scanned items. |
Type Parameters
Name | Description |
---|---|
T | The type of items to scan. |
ScanPaginatedByAsync<T>(ScanRequest, CancellationToken)
Scans the DynamoDB table based on the specified scan request and returns a paginated collection of items.
Declaration
public Task<PagedCollection<T>> ScanPaginatedByAsync<T>(ScanRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
ScanRequest | request | The scan request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task<PagedCollection<T>> | A paginated collection of items based on the scan request. |
Type Parameters
Name | Description |
---|---|
T | The type of items to scan. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the request is null. |
TransactWriteItemsAsync(TransactionWriteRequest, CancellationToken)
Writes a batch of transactional write items to the DynamoDB table.
Declaration
public Task TransactWriteItemsAsync(TransactionWriteRequest request, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
TransactionWriteRequest | request | The transaction write request. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task | Task representing the asynchronous operation. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the request is null. |
BusinessException | Thrown when the number of transactItems is invalid. |
UpdateAsync(string, Dictionary<string, AttributeValue>, Dictionary<string, AttributeValueUpdate>, CancellationToken)
Updates an item in the DynamoDB table based on the provided parameters.
Declaration
protected Task UpdateAsync(string tableName, Dictionary<string, AttributeValue> key, Dictionary<string, AttributeValueUpdate> attributeUpdates, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | tableName | The name of the DynamoDB table. |
Dictionary<string, AttributeValue> | key | The key of the item to update. |
Dictionary<string, AttributeValueUpdate> | attributeUpdates | The attribute updates for the item. |
CancellationToken | cancellationToken | Cancellation token to cancel the operation. |
Returns
Type | Description |
---|---|
Task | Task representing the asynchronous update operation. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when key or attributeUpdates is null. |
UpdateAsync<T>(T, CancellationToken)
This method will perform an update operation on the table. The operation is based on the primary key and type is PUT.
Declaration
public Task<T> UpdateAsync<T>(T instance, CancellationToken cancellationToken = default) where T : class, new()
Parameters
Type | Name | Description |
---|---|---|
T | instance | The instance that you want to update |
CancellationToken | cancellationToken | A cancellation token. |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | The instance updated. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |