Code Monkey home page Code Monkey logo

azure-cosmos-dotnet-repository's Introduction

build CodeQL NuGet Nuget .NET code metrics Discord

All Contributors

Azure Cosmos DB Repository .NET SDK

This package wraps the NuGet: Microsoft.Azure.Cosmos package, exposing a simple dependency-injection enabled IRepository<T> interface.

Documentation

The core library IEvangelist.Azure.CosmosRepository and IEvangelist.Azure.CosmosEventSourcing both host there own documentation site. See below:

Cosmos Repository

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:

[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):

[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

Getting started

  1. Create an Azure Cosmos DB SQL resource.

  2. 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.

  3. Call AddCosmosRepository:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddCosmosRepository();
    }

    The optional setupAction allows consumers to manually configure the RepositoryOptions object:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddCosmosRepository(
            options =>
            {
                options.CosmosConnectionString = "< connection string >";
                options.ContainerId = "data-store";
                options.DatabaseId = "samples";
            });
    }
  4. Define your object graph, objects must inherit Item, for example:

    using Microsoft.Azure.CosmosRepository;
    
    public class Person : Item
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
  5. Ask for an instance of IRepository<TItem>, in this case the TItem is Person:

    using Microsoft.Azure.CosmosRepository;
    
    public class Consumer
    {
        readonly IRepository<Person> _repository;
    
        public Consumer(IRepository<Person> repository) =>
            _repository = repository;
    
        // Use the repo...
    }
  6. Perform any of the operations on the _repository instance, create Person records, update them, read them, or delete.

  7. Enjoy!

Samples

Visit the Microsoft.Azure.CosmosRepository.Samples directory for samples on how to use the library with:

Deep-dive video

A deep dive into the Azure Cosmos DB repository pattern NET SDK

Cosmos Repository Crash Course

Discord

Get extra support on our dedicated Discord channel.

alt Join the conversation

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

David Pine
David Pine

๐Ÿ’ป โš ๏ธ ๐Ÿ’ก ๐Ÿ‘€
Invvard
Invvard

โš ๏ธ ๐Ÿ’ป
Richard Mercer
Richard Mercer

๐Ÿ’ป
Daniel Marbach
Daniel Marbach

๐Ÿ’ป
Manuel Sidler
Manuel Sidler

๐Ÿ’ป
Dave Brock
Dave Brock

๐Ÿ“– ๐Ÿ’ป
Cagdas Erman Afacan
Cagdas Erman Afacan

๐Ÿ’ป ๐Ÿ’ก
dcuccia
dcuccia

๐Ÿ’ป
VeryCautious
VeryCautious

๐Ÿ’ป โš ๏ธ
Billy Mumby
Billy Mumby

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Michael Zhang
Michael Zhang

๐Ÿค” ๐Ÿ’ป
Shay Rojansky
Shay Rojansky

๐Ÿ‘€
Junior Macedo
Junior Macedo

๐Ÿ’ป ๐Ÿค”
Emre KARA
Emre KARA

๐Ÿ’ป
Brad Westness
Brad Westness

๐Ÿ‘€
Matt Stannett
Matt Stannett

๐Ÿ’ป ๐Ÿ“– โš ๏ธ
mustafarabie
mustafarabie

๐Ÿ’ป โš ๏ธ
Robert Bennett
Robert Bennett

โš ๏ธ ๐Ÿ’ป
Rabosa616
Rabosa616

๐Ÿ’ป โš ๏ธ ๐Ÿ“–
Adam Storr
Adam Storr

๐Ÿ’ป โš ๏ธ
Kevin Benton
Kevin Benton

๐Ÿ’ป โš ๏ธ
Filip Persson
Filip Persson

๐Ÿ’ป โš ๏ธ
A.F.M. Noorullah
A.F.M. Noorullah

๐Ÿ“–
Ion Dormenco
Ion Dormenco

๐Ÿ’ป
Martin Oehlert
Martin Oehlert

๐Ÿ’ป
Evan Johnson
Evan Johnson

๐Ÿ’ป โš ๏ธ
Phil Reed
Phil Reed

โš ๏ธ ๐Ÿ’ป ๐Ÿ“–
dnitsch
dnitsch

๐Ÿค”
Sean Farrow
Sean Farrow

๐Ÿค”
stormbringer766
stormbringer766

๐Ÿ’ป โš ๏ธ
Joel Turner
Joel Turner

๐Ÿ’ป
Ross
Ross

๐Ÿ›
John Belcher
John Belcher

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

azure-cosmos-dotnet-repository's People

Contributors

afacanerman avatar allcontributors[bot] avatar beigebadger avatar boylec avatar danielmarbach avatar daveabrock avatar dcuccia avatar dependabot[bot] avatar emrekara37 avatar evancjohnson avatar fffffatah avatar filipmhpersson avatar github-actions[bot] avatar idormenco avatar ievangelist avatar imgbot[bot] avatar invvard avatar joelsteventurner avatar kevin-benton avatar manuelsidler avatar mo2k4 avatar mrfootoyou avatar mumby0168 avatar philip-reed avatar rabosa616 avatar richmercer avatar robertbennett1998 avatar stormbringer766 avatar verycautious avatar westdiscgolf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.