Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ievangelist/azure-cosmos-dotnet-repository
Wraps the .NET SDK for Azure Cosmos DB abstracting away the complexity, exposing a simple CRUD-based repository pattern
https://github.com/ievangelist/azure-cosmos-dotnet-repository
azure-cosmos-db crud dotnet hacktoberfest repository-pattern sdk
Last synced: 4 days ago
JSON representation
Wraps the .NET SDK for Azure Cosmos DB abstracting away the complexity, exposing a simple CRUD-based repository pattern
- Host: GitHub
- URL: https://github.com/ievangelist/azure-cosmos-dotnet-repository
- Owner: IEvangelist
- License: mit
- Created: 2020-09-16T17:07:42.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-09T20:44:22.000Z (15 days ago)
- Last Synced: 2024-12-14T16:00:21.653Z (11 days ago)
- Topics: azure-cosmos-db, crud, dotnet, hacktoberfest, repository-pattern, sdk
- Language: C#
- Homepage: https://ievangelist.github.io/azure-cosmos-dotnet-repository
- Size: 15.4 MB
- Stars: 313
- Watchers: 12
- Forks: 92
- Open Issues: 37
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
![build](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/workflows/build/badge.svg) ![CodeQL](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/workflows/CodeQL/badge.svg) [![NuGet](https://img.shields.io/nuget/v/IEvangelist.Azure.CosmosRepository.svg?style=flat&label=NuGet%20version)](https://www.nuget.org/packages/IEvangelist.Azure.CosmosRepository) ![Nuget](https://img.shields.io/nuget/dt/IEvangelist.Azure.CosmosRepository?color=blue&label=NuGet%20downloads&logo=nuget) [![.NET code metrics](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/actions/workflows/code-metrics.yml/badge.svg)](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/actions/workflows/code-metrics.yml) [![Discord](https://img.shields.io/discord/868239483529723914.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.com/invite/qMXrX4shAv)
[![All Contributors](https://img.shields.io/badge/all_contributors-35-orange.svg?style=flat-square)](#contributors-)# Azure Cosmos DB Repository .NET SDK
This package wraps the [NuGet: Microsoft.Azure.Cosmos package](https://www.nuget.org/packages/Microsoft.Azure.Cosmos),
exposing a simple dependency-injection enabled `IRepository` interface.## Documentation
The core library `IEvangelist.Azure.CosmosRepository` and `IEvangelist.Azure.CosmosEventSourcing` both host there own documentation site. See below:
* [`IEvangelist.Azure.CosmosRepository Documentation`](https://ievangelist.github.io/azure-cosmos-dotnet-repository/1-getting-started/)
* [`IEvangelist.Azure.CosmosEventSourcing Documentation`](https://mumby0168.github.io/cosmos-event-sourcing-docs/)![Cosmos Repository](CosmosRepository.png)
The repository is responsible for all of the create, read, update, and delete (CRUD) operations on objects `where T : Item`. The `Item` type adds
several properties, one which is a globally unique identifier defined as:```csharp
[JsonProperty("id")]
public string Id { get; set; } = Guid.NewGuid().ToString();
```Additionally, a type property exists which indicates the subclass name (this is used for filtering implicitly on your behalf):
```csharp
[JsonProperty("type")]
public string Type { get; set; }
```Finally, a partition key property is used internally to manage partitioning on your behalf. This can optionally be overridden on an item per item basis.
📣 [Azure Cosmos DB - Official Blog](https://devblogs.microsoft.com/cosmosdb/azure-cosmos-db-repository-net-sdk-v-1-0-4)
## Getting started
1. Create an Azure Cosmos DB SQL resource.
1. Obtain the resource connection string from the **Keys** blade, be sure to get a connection string and not the key - these are different. The connection string is a compound key and endpoint URL.
1. Call `AddCosmosRepository`:```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddCosmosRepository();
}
```The optional `setupAction` allows consumers to manually configure the `RepositoryOptions` object:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddCosmosRepository(
options =>
{
options.CosmosConnectionString = "< connection string >";
options.ContainerId = "data-store";
options.DatabaseId = "samples";
});
}
```1. Define your object graph, objects must inherit `Item`, for example:
```csharp
using Microsoft.Azure.CosmosRepository;public class Person : Item
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
```1. Ask for an instance of `IRepository`, in this case the `TItem` is `Person`:
```csharp
using Microsoft.Azure.CosmosRepository;public class Consumer
{
readonly IRepository _repository;public Consumer(IRepository repository) =>
_repository = repository;// Use the repo...
}
```1. Perform any of the operations on the `_repository` instance, create `Person` records, update them, read them, or delete.
1. Enjoy!## Samples
Visit the `Microsoft.Azure.CosmosRepository.Samples` [directory](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/tree/main/samples) for samples on how to use the library with:
- [Azure Functions](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/tree/main/samples/Microsoft.Azure.CosmosRepository/AzureFunctionTier)
- [Services](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/tree/main/samples/Microsoft.Azure.CosmosRepository/ServiceTier)
- [Controllers (web apps)](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/tree/main/samples/Microsoft.Azure.CosmosRepository/WebTier)
- [Paging](https://github.com/IEvangelist/azure-cosmos-dotnet-repository/tree/main/samples/Microsoft.Azure.CosmosRepository/Paging)## Deep-dive video
[![A deep dive into the Azure Cosmos DB repository pattern NET SDK](images/deep-dive-talk.png)](https://www.youtube.com/watch?v=izdnmBrTweA)
[![Cosmos Repository Crash Course](images/dotnet-docs-show.jpeg)](https://www.youtube.com/watch?v=_rsVwc4n8Ps)
## Discord
Get extra support on our dedicated Discord channel.
[![alt Join the conversation](https://img.shields.io/discord/868239483529723914.svg "Discord")](https://discord.com/invite/qMXrX4shAv)
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
David Pine
💻 ⚠️ 💡 👀
Invvard
⚠️ 💻
Richard Mercer
💻
Daniel Marbach
💻
Manuel Sidler
💻
Dave Brock
📖 💻
Cagdas Erman Afacan
💻 💡
dcuccia
💻
VeryCautious
💻 ⚠️
Billy Mumby
💻 📖 🤔
Michael Zhang
🤔 💻
Shay Rojansky
👀
Junior Macedo
💻 🤔
Emre KARA
💻
Brad Westness
👀
Matt Stannett
💻 📖 ⚠️
mustafarabie
💻 ⚠️
Robert Bennett
⚠️ 💻
Rabosa616
💻 ⚠️ 📖
Adam Storr
💻 ⚠️
Kevin Benton
💻 ⚠️
Filip Persson
💻 ⚠️
A.F.M. Noorullah
📖
Ion Dormenco
💻
Martin Oehlert
💻
Evan Johnson
💻 ⚠️
Phil Reed
⚠️ 💻 📖
dnitsch
🤔
Sean Farrow
🤔
stormbringer766
💻 ⚠️
Joel Turner
💻
Ross
🐛
John Belcher
📖
Victor Marante
💻
Mateusz Kumpf
💻 ⚠️
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!