IEvangelist.Azure.CosmosRepository · MIT licensed
Azure Cosmos DB,
the repository way.
A dependency-injection-friendly IRepository<T>
wrapper around the official Microsoft.Azure.Cosmos SDK.
Configure once, inject everywhere, ship faster.
dotnet add package IEvangelist.Azure.CosmosRepository dotnet add package IEvangelist.Azure.CosmosRepository Built on the official SDK
Every base type, every option, and every fluent extension is documented and backed by working samples in the repo.
Repository pattern
Inject IRepository<T> for any item type and get full create / read / update / delete with batching and paging.
Read the docsItem types
Pick the base class that fits — Item, EtagItem, TimeStampedItem, TimeToLiveItem, or FullItem.
Read the docsContainer configuration
Fluent options for partitioning, throughput, TTL, change-feed, and unique keys.
Read the docsSpecification queries
Encapsulate filters, ordering, and paging as reusable Specification classes.
Read the docsChange feed
Process container changes with IItemChangeFeedProcessor and the AspNetCore hosted service.
Read the docsProduction-ready
Health checks, eager container init, structured logging — everything you need for prod.
Read the docs
Three steps from
dotnet add to running
Install the package, register the services, and inject
IRepository<T> wherever you need data access.
- Step 1
Wire it up once
Call AddCosmosRepository on your IServiceCollection. One call configures the Cosmos client, options, and registers IRepository<T> for every item you define.
Register the repository using Microsoft.Azure.CosmosRepository;var builder = WebApplication.CreateBuilder(args);builder.Services.AddCosmosRepository(options =>{options.CosmosConnectionString = "<connection string>";options.DatabaseId = "samples";options.ContainerId = "data-store";}); - Step 2
Model your data
Inherit from Item (or EtagItem, TimeToLiveItem, FullItem). The base type owns the id, type discriminator, and partition key so your class stays focused on the domain.
Define an item using Microsoft.Azure.CosmosRepository;public class Person : Item{public string FirstName { get; set; } = null!;public string LastName { get; set; } = null!;} - Step 3
Use it anywhere
Inject IRepository<Person> into your services, endpoints, or background workers. Predicates, batching, paging, and the Specification pattern are all built in.
Inject and use public class PeopleService(IRepository<Person> repository){public Task<Person> CreateAsync(Person person) =>repository.CreateAsync(person).AsTask();public Task<IEnumerable<Person>> GetWithoutMiddleNamesAsync() =>repository.GetAsync(p => p.MiddleName == null).AsTask();}
Want more? Browse the full docs or jump straight to Getting started.