Skip to content

william-liebenberg/AzureGems

Repository files navigation

AzureGems

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

Summary of all the AzureGems libraries. For more detailed information check out the libraries individually.

AzureGems.CosmosDB

View Code

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");
		});
});

AzureGems.Repository.Abstractions

View Code

Interface for a generic Repository Pattern.

Sample implementation: AzureGems.Repository.CosmosDB

AzureGems.Repository.CosmosDB

View Code

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.

AzureGems.SpendOps.Abstractions

View Code

Interfaces necessary for implementing #SpendOps into your ORM/Data Layers and Test Libraries.

Sample implementation using Cosmos DB: AzureGems.SpendOps.CosmosDB

AzureGems.SpendOps.CosmosDB

View Code

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.

AzureGems.SpendOps.CosmosDB.ChargeTrackers.TableStorage

View Code

Charge Tracker using Azure Table Storage for persisting #SpendOps data.

AzureGems.SpendOps.CosmosDB.ChargeTrackers.CosmosDB

View Code

Charge Tracker using Azure Cosmos DB for persisting #SpendOps data.

TODO: Finish Code

AzureGems.MediatR.Extensions

View Code

Simple but useful extensions for MediatR

  • Specializes IRequest into IQuery and ICommand
  • Specializes IRequestHandler into IQueryHandler and ICommandHandler

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages