A collection of interfaces and classes for accessing data from databases and other data sources
Read data from a repository (data source)
Retrieve a single object with the given id
Retrieve a list of objects with the given ids
Query for a list of objects that match the given expression
public IAsyncEnumerable<Customer> GetCustomers(string city)
{
return _reader.Get( (c)=> c.City == city);
}
Write data to a repository (data source)
Insert a new object into the repository
Insert a list of objects into the repository
Update a single object with a guard
_writer.Update(customer, (c)=> c.Status == "active");
Retrieve a list of objects that match the given query and update the given properties. Returns the number of items updated.
// Change city of all the items with city of "Lower Junction" to "Springfield"
_writer.Update( new { City = "Springfield" }, (item)=> item.City == "Lower Junction");
Task<long> Update(Func<TValue, Task<(bool Update, bool Continue)>> update, Expression<Func<TValue, bool>> query);
Retrieve a list of objects that match the given query and updates using the given lambda expression to modify properties. Returns the number of items updated.
// Change city of all the items with city of "Lower Junction" to "Springfield"
_writer.Update( (i)=>
{
i.City = "Springfield",
return Task.FromResult((true, true));
},
new { City = "Springfield" }, (item)=> item.City == "Lower Junction");
Delete a single object
Delete a list of objects that match the given query. Returns the number of items deleted.
_writer.Delete( (item)=> item.Status == "Archived");
Retrieve read and write repository interfaces from a database. A repository may be a sql database table or a collection in a NoSql database.
IReadRepository<TID, TValue> GetRepositoryReader<TID, TValue>(string repoName, IIdentifierStrategy<TID> strategy = null) where TValue : IIdentifiable<TID>
Retrieve a reader for a repository with the given name and identifier strategy
IWriteRepository<TID, TValue> GetRepositoryWriter<TID, TValue>(string repoName, IIdentifierStrategy<TID> strategy = null) where TValue : IIdentifiable<TID>
Retrieve a writer for a repository with the given name and identifier strategy
(extension) IReadRepository<TID, TValue> GetRepositoryReader<TID, TValue>(string repoName, string partitionKey) where TValue : IIdentifiable
Retrieve a reader for a repository with the given name using a fixed identifier strategy
(extension) IWriteRepository<TID, TValue> GetRepositoryWriter<TID, TValue>(string repoName, string partitionKey) where TValue : IIdentifiable
Retrieve a writer for a repository with the given name using a fixed identifier strategy
The value type for a respository must derive from the interface.
The read and write interfaces take a single identifier but certain kinds of repositories/databases might also take a partition key. This interface specifies how to extract the partition key.
If a repository is partitioned then the value type for a respository must derive from the interface.
Represents an object with a repository item id and a partition key
Provides a way to cache the contents of a repository (as needed) using another repository, usually a memory only repository.
A model class that contains an identifier and a partiton key.
Represents a strategy where the key passed into a repository reader/writer is a delimited id and partition key, e.g. "id;partitionkey"
Represents a strategy where the key passed into a repository reader/writer is a fixed partition key and the key is the identifier alone.
An exception to indicate when an object was not found