NOTE: As of v3 Azure Gems Libraries have been upgraded to .NET 7.0
Check out my video on SSW TV about #SpendOps and CosmosDB:
Summary of all the AzureGems libraries. For more detailed information check out the libraries individually.
Library for getting started with Cosmos DB quickly and easily.
- Simple connection config
- Define DB Container properties:
- model type
- container name
- throughput
- partition key path
- and more...
For example the following code can be added to your .NET/ASP.NET Core Startup.cs
file to connect to Cosmos DB and ensure that the required containers are created/exists in the database:
services.AddCosmosDb(builder =>
{
builder
.Connect(endPoint: "<YOUR COSMOS DB ENDPOINT>", authKey: "<YOUR COSMOSDB AUTHKEY>")
.UseDatabase(databaseId: "MyDatabase")
.WithSharedThroughput(4000)
.WithContainerConfig(c =>
{
c.AddContainer<Vehicle>(containerId: "Cars", partitionKeyPath: "/brand", queryByDiscriminator: false, throughput: 20000);
c.AddContainer<Receipt>(containerId: "Receipts", partitionKeyPath: "/id");
c.AddContainer<Accessory>(containerId: "Accessories", partitionKeyPath: "/category");
});
});
Interface for a generic Repository Pattern.
Sample implementation: AzureGems.Repository.CosmosDB
Cosmos DB specific implementation of the generic Repository Pattern. CosmosDbContainerRepository.cs
implements the IRepository<T>
interface.
This library also aims to provide EFCore-like DbContext
's by simply declaring one or more IRepository<T>
(DbSet
in EFCore) inside a CosmosContext
class.
For example:
public class LittleNorthwindCosmosContext : CosmosContext
{
public IRepository<Customer> Customers { get; set; }
public IRepository<Order> Orders { get; set; }
public IRepository<Invoice> Invoices { get; set; }
}
The CosmosDbContainer
implementation already contains the definition of each container (see AzureGems.CosmosDB) and can instantiate the IRepository<T>
instances via reflection when the CosmosContext
is resolved from the ServiceCollection
.
The instance of your CosmosContext
can now be used in your application's services or controllers by constructor injection.
Interfaces necessary for implementing #SpendOps into your ORM/Data Layers and Test Libraries.
Sample implementation using Cosmos DB: AzureGems.SpendOps.CosmosDB
Cosmos DB implementations for IChargeTracker
and ISpendTestChargeTracker
.
The TrackedCosmosDbContainer
collects RequestCharge
values from all the CosmosDbResponse<T>
objects returned from the CRUD operations performed by the CosmosDbContainer
implementation.
Implementations of IChargeTracker
and ISpendTestChargeTracker
are configured in the Composition Root for your Application or Test Library.
For applications an implementation of IChargeTracker
is used.
For unit/integration/spend tests an implementation of ISpendTestChargeTracker
is configured and registered.
Charge Tracker using Azure Table Storage for persisting #SpendOps data.
Charge Tracker using Azure Cosmos DB for persisting #SpendOps data.
TODO: Finish Code
Simple but useful extensions for MediatR
- Specializes
IRequest
intoIQuery
andICommand
- Specializes
IRequestHandler
intoIQueryHandler
andICommandHandler