{"id":25002572,"url":"https://github.com/siberaindustries/si.unitofwork","last_synced_at":"2025-03-29T21:15:06.785Z","repository":{"id":65661009,"uuid":"300446532","full_name":"SiberaIndustries/SI.UnitOfWork","owner":"SiberaIndustries","description":"A lightweight and flexible Repository / UnitOfWork framework.","archived":false,"fork":false,"pushed_at":"2023-02-02T23:35:34.000Z","size":115,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-27T14:32:19.869Z","etag":null,"topics":["asp-net-core","entity-framework-core","object-relational-mapper","orm","repositories","repository","unitofwork"],"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/SiberaIndustries.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}},"created_at":"2020-10-01T23:03:34.000Z","updated_at":"2023-01-28T23:14:46.000Z","dependencies_parsed_at":"2023-02-18T01:31:25.992Z","dependency_job_id":null,"html_url":"https://github.com/SiberaIndustries/SI.UnitOfWork","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiberaIndustries%2FSI.UnitOfWork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiberaIndustries%2FSI.UnitOfWork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiberaIndustries%2FSI.UnitOfWork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiberaIndustries%2FSI.UnitOfWork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SiberaIndustries","download_url":"https://codeload.github.com/SiberaIndustries/SI.UnitOfWork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246243548,"owners_count":20746311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["asp-net-core","entity-framework-core","object-relational-mapper","orm","repositories","repository","unitofwork"],"created_at":"2025-02-04T21:53:02.535Z","updated_at":"2025-03-29T21:15:06.761Z","avatar_url":"https://github.com/SiberaIndustries.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SI.UnitOfWork\n\n[![NuGet](https://img.shields.io/nuget/v/SI.UnitOfWork.svg)](https://www.nuget.org/packages/SI.UnitOfWork)\n[![NuGet](https://img.shields.io/nuget/v/SI.UnitOfWork.EntityFrameworkCore.svg)](https://www.nuget.org/packages/SI.UnitOfWork.EntityFrameworkCore)\n[![.NET Core](https://github.com/SiberaIndustries/SI.UnitOfWork/workflows/.NET%20Core/badge.svg)](https://github.com/SiberaIndustries/SI.UnitOfWork/actions?query=workflow%3A%22.NET+Core%22)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=SiberaIndustries_SI.UnitOfWork\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=SiberaIndustries_SI.UnitOfWork)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=SiberaIndustries_SI.UnitOfWork\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=SiberaIndustries_SI.UnitOfWork)\n\n## Introduction\n\nMost of the repository pattern libraries for .NET or .NET Core depend on the Entity Framework.\nUnlike all these frameworks, the `SI.UnitOfWork` has **no such dependencies** and follows the strict paradigms of the repository pattern.\nBut if you want, `SI.UnitOfWork.EntityFrameworkCore` provides a complete and ready-to-use library for **SqLite**, **PostgreSQL**, **SQL Server** and the **InMemory** provider of Entity Framework.\n\n---\n\n## Getting Started with `SI.UnitOfWork`\n\n### 1. Install and reference the NuGet package\n\n```cs\nInstall-Package SI.UnitOfWork\n```\n\n### 2. Edit your `ConfigureServices()` method in `Startup.cs`\n\n```cs\npublic void ConfigureServices(IServiceCollection services)\n{\n    // ..\n    services.AddDbContext\u003cIDbContext, SampleContext\u003e(o =\u003e o.UseInMemoryDatabase(\"mem-db\"));\n    services.AddUnitOfWork\u003cSampleContext\u003e();\n    services.AddScoped(typeof(IRepository\u003c\u003e), typeof(GenericRepository\u003c\u003e));\n    services.AddScoped(typeof(ICustomRepository), typeof(CustomRepository));\n    // ..\n}\n```\n\n### 2. Inject and use\n\n```cs\npublic class SampleClass\n{   \n    // Opt. 1. Inject a UoW for regular DB read and write operations\n    // Opt. 2. Inject a UoW-Factory in case you work with multiple databases\n    // Opt. 3. Inject a RepositoryFactory to get read-only repositories\n    public SampleClass(\n        IUnitOfWork unitOfWork, \n        IUnitOfWorkFactory\u003cSampleContext\u003e unitofWorkFactory,\n        IRepositoryFactory\u003cSampleContext\u003e repositoryFactory)    \n    {\n        IRepository\u003cPerson\u003e personRepository;   // Register generic repositories manually!\n        ICustomRepository customRepository;     // Register custom repositories manually!\n\n\n        // Opt. 1\n        personRepository = unitOfWork.GetRepository\u003cPerson\u003e();\n        customRepository = unitOfWork.GetRepository\u003cPerson, ICustomRepository\u003e();\n        // .. do work\n        unitOfWork.SaveChanges();\n\n\n        // Opt. 2\n        using var uow = unitofWorkFactory.GetUnitOfWork();\n        personRepository = uow.GetRepository\u003cPerson\u003e();\n        customRepository = uow.GetRepository\u003cPerson, ICustomRepository\u003e();\n        // .. do work\n        uow.SaveChanges();\n\n\n        // Opt. 3\n        personRepository = repositoryFactory.GetRepository\u003cPerson\u003e();\n        customRepository = repositoryFactory.GetRepository\u003cPerson, ICustomRepository\u003e();\n        // No SaveChanges available!\n    }\n}\n```\n\n---\n\n## Getting Started with `SI.UnitOfWork.EntityFrameworkCore`\n\n### 1. Install and reference the NuGet package\n\n```cs\nInstall-Package SI.UnitOfWork.EntityFrameworkCore\n```\n\n### 2. Edit your `ConfigureServices()` method in `Startup.cs`\n\n```cs\npublic void ConfigureServices(IServiceCollection services)\n{\n    // ..\n    services.AddDbContext\u003cEFContext\u003e(o =\u003e o.UseInMemoryDatabase(\"mem-db\");\n    services.AddEFUnitOfWork();\n    services.AddScoped(typeof(ICustomRepository), typeof(CustomRepository));\n    // ..\n}\n```\n\n### 2. Inject and use\n\n```cs\npublic class SampleClass\n{\n    public SampleClass(IUnitOfWork unitOfWork)\n    {\n        IRepository\u003cPerson\u003e personRepository;   // Generic repositories are automatically registered!\n        ICustomRepository customRepository;     // Register custom repositories manually!\n\n\n        personRepository = unitOfWork.GetRepository\u003cPerson\u003e();\n        customRepository = unitOfWork.GetRepository\u003cPerson, ICustomRepository\u003e();\n        // .. do work\n        unitOfWork.SaveChanges();\n    }\n}\n```\n\n## Open Source License Acknowledgements and Third-Party Copyrights\n\n- Icon made by [Freepik](https://www.flaticon.com/authors/freepik)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiberaindustries%2Fsi.unitofwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiberaindustries%2Fsi.unitofwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiberaindustries%2Fsi.unitofwork/lists"}