{"id":37048684,"url":"https://github.com/brunobrandes/cosmos-db-sql-api-repository","last_synced_at":"2026-01-14T05:39:44.626Z","repository":{"id":68299819,"uuid":"227252442","full_name":"brunobrandes/cosmos-db-sql-api-repository","owner":"brunobrandes","description":"A generic implementation of Repository Pattern in C# to Cosmos DB SQL API","archived":false,"fork":false,"pushed_at":"2024-07-09T21:21:36.000Z","size":46,"stargazers_count":13,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-01T05:25:32.001Z","etag":null,"topics":["azure-cosmos-db","database","genericrepository","repository-pattern"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brunobrandes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-11T01:49:38.000Z","updated_at":"2024-12-01T16:10:36.000Z","dependencies_parsed_at":"2023-07-25T20:01:11.851Z","dependency_job_id":null,"html_url":"https://github.com/brunobrandes/cosmos-db-sql-api-repository","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brunobrandes/cosmos-db-sql-api-repository","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobrandes%2Fcosmos-db-sql-api-repository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobrandes%2Fcosmos-db-sql-api-repository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobrandes%2Fcosmos-db-sql-api-repository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobrandes%2Fcosmos-db-sql-api-repository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brunobrandes","download_url":"https://codeload.github.com/brunobrandes/cosmos-db-sql-api-repository/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobrandes%2Fcosmos-db-sql-api-repository/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28410993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-cosmos-db","database","genericrepository","repository-pattern"],"created_at":"2026-01-14T05:39:44.142Z","updated_at":"2026-01-14T05:39:44.621Z","avatar_url":"https://github.com/brunobrandes.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Azure Cosmos DB Sql Api Repository\nA generic implementation of Repository Pattern in C# to Cosmos DB SQL API\n\n[![Build status](https://ci.appveyor.com/api/projects/status/0i6s33kw3y87tkb2?svg=true)](https://ci.appveyor.com/project/brunobrandes/azure-cosmos-db-repository)\n\n## Introduction \n\nThis project implements and demonstrates how to use the repository pattern with Azure Cosmos DB [SQL API](https://docs.microsoft.com/en-us/azure/cosmos-db/create-sql-api-dotnet-v4).\n\n### Repository Pattern\n\nMartin Fowler describes in the book [Patterns of Enterprise Application Architecture](https://amzn.to/38k9VsE) a repository as follows:\n\n\u003e A repository performs the tasks of an intermediary between the domain model layers and data mapping, acting in a similar way to a set of \n\u003e domain objects in memory. Client objects declaratively build queries and send them to the repositories for answers. Conceptually, a\n\u003e repository encapsulates a set of objects stored in the database and operations that can be performed on them, providing a way that is \n\u003e closer to the persistence layer. Repositories, also, support the purpose of separating, clearly and in one direction, the dependency \n\u003e between the work domain and the data allocation or mapping.\n\n#### Benefits of Repository Pattern\n\n1. Centralizes data, business and service logic.\n2. Unit tests independent off the database layer.\n3. Modify the data access logic or business access logic without change the repository logic.\n\n#### Generic Repository Pattern\n\nGeneric repository pattern is aimed at reducing repetition replacing it with abstractions or using data normalization - [Don’t repeat yourself](https://en.wikipedia.org/wiki/Don't_repeat_yourself)\n\n#### Do you really need it?\n\nI've separated some articles for you to decide for yourself.\n\n* [Repository Pattern Benefits: Why We Should Consider It](https://bit.ly/2SMWqsm)\n* [The generic repository is just a lazy anti-pattern](https://bit.ly/2XJca3c)\n* [What are the benefits of using Repositories?](https://bit.ly/2EP3cdz)\n* [Ditch the Repository Pattern Already](https://bit.ly/2SHupT6)\n\n### Azure Cosmos DB\n\nAzure Cosmos DB is Microsoft's globally distributed, multi-model database service and enables you to using your favorite API among SQL, MongoDB, Cassandra, Tables, or Gremlin. \n\n[![Global scale with Azure Cosmos DB](https://i.imgur.com/xcxKPQa.png)](https://docs.microsoft.com/en-us/azure/cosmos-db/introduction)\n\n## Getting Started\n\n1.\tInstallation process\n\nTo install Cosmos.Db.Sql.Api.Repository, run the following command in the [Package Manager Console](https://docs.nuget.org/consume/package-manager-console)\n \u003ePM\u003e Install-Package Cosmos.Db.Sql.Api.Repository -Version 1.0.0-preview\n\nCosmos.Db.Sql.Api.Repository has GenericRepository. Through **CosmosClient (preview)** GenericRepository class implement base [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) methods (AddAsync, UpdateAsync, DeleteAsync, GetByIdAsync, GetAllAsyn).\n\n2.\tSoftware dependencies\n\n [Cosmos.Db.Sql.Api.Repository](https://www.nuget.org/packages/Cosmos.Db.Sql.Api.Repository/) have [Cosmos.Db.Sql.Api.Domain](https://www.nuget.org/packages/Cosmos.Db.Sql.Api.Domain/) dependency. \n The domain layer have IGenericRepository and Entity base class.\n \n ```csharp\npublic abstract class Entity\n{\n\t/// \u003csummary\u003e\n\t/// Default document entity identifier\n\t/// \u003c/summary\u003e\n\t[JsonProperty(PropertyName = \"id\")]\n\tpublic string Id { get; set; }\n\t\n\t/// \u003csummary\u003e\n\t/// Data time to live\n\t/// \u003c/summary\u003e\n\t[JsonProperty(PropertyName = \"ttl\")]\n\tpublic int Ttl { get; set; }\n\t\n\t/// \u003csummary\u003e\n\t/// Entity\n\t/// \u003c/summary\u003e\n\t/// \u003cparam name=\"generateId\"\u003eGenerate id\u003c/param\u003e\n\tpublic Entity(bool generateId)\n\t{\n\t\tSetDefaultTimeToLive();\n\t\n\t\tif (generateId)\n\t\t\tthis.Id = Guid.NewGuid().ToString();\n\t}\n\t\n\t/// \u003csummary\u003e\n\t/// Set a default data time to live\n\t/// \u003c/summary\u003e\n\tpublic virtual void SetDefaultTimeToLive()\n\t{\n\t\tTtl = -1;\n\t}\n }\n ```\n \n## Usage\n\nAfter install [Cosmos.Db.Core.Repository](https://www.nuget.org/packages/Cosmos.Db.Core.Repository/) you need:\n\n1. Create Entity\n\nEntity is a Document (JSON) data. Ex:\n\n```csharp\npublic class Foo : Entity\n{\n    public Foo()\n        : base(true)\n    {\n    }\n\n    public string City { get; set; }\n    public string Neighborhood { get; set; }\n}\n```\n2. Create Repository interface\n```csharp\npublic interface IFooRepository : IGenericRepository\u003cFoo\u003e\n{\n}\n```\n3. Implement Repository\n```csharp\npublic class FooRepository : GenericRepository\u003cDomain.Entities.Foo\u003e, IFooRepository\n{\n    public readonly CosmosClient _cosmosClient;\n\n    public FooRepository(CosmosClient cosmosClient) :\n        base(cosmosClient)\n    {\n        _cosmosClient = cosmosClient;\n    }\n\n    public override string DatabaseId =\u003e \"Foo\";\n    public override string ContainerId =\u003e \"Foo\";\n}\n```\n4. Configure Dependecy Injection\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services\n        .AddScoped\u003cIFooRepository\u003e(x =\u003e new FooRepository(new CosmosClient(\n            Configuration.GetConnectionString(\"DefaultConnection\"))));\n}\n```\nSee the [Foo Project sample](https://bit.ly/36dVDrC) which contains implementation. Run **Foo.Ui.Api** and execute postman (*postman-collection.json*).\n## License\n\nThis software is open source, licensed under the MIT License. \u003c/br\u003e\nSee [LICENSE](https://github.com/brunobrandes/cosmos-db-sql-api-repository/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunobrandes%2Fcosmos-db-sql-api-repository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunobrandes%2Fcosmos-db-sql-api-repository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunobrandes%2Fcosmos-db-sql-api-repository/lists"}