SI.UnitOfWork 2.1.0

dotnet add package SI.UnitOfWork --version 2.1.0
NuGet\Install-Package SI.UnitOfWork -Version 2.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SI.UnitOfWork" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SI.UnitOfWork --version 2.1.0
#r "nuget: SI.UnitOfWork, 2.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SI.UnitOfWork as a Cake Addin
#addin nuget:?package=SI.UnitOfWork&version=2.1.0

// Install SI.UnitOfWork as a Cake Tool
#tool nuget:?package=SI.UnitOfWork&version=2.1.0

SI.UnitOfWork

NuGet NuGet .NET Core Quality Gate Status Coverage

Introduction

Most of the repository pattern libraries for .NET or .NET Core depend on the Entity Framework. Unlike all these frameworks, the SI.UnitOfWork has no such dependencies and follows the strict paradigms of the repository pattern. But 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.


Getting Started with SI.UnitOfWork

1. Install and reference the NuGet package

Install-Package SI.UnitOfWork

2. Edit your ConfigureServices() method in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    // ..
    services.AddDbContext<IDbContext, SampleContext>(o => o.UseInMemoryDatabase("mem-db"));
    services.AddUnitOfWork<SampleContext>();
    services.AddScoped(typeof(IRepository<>), typeof(GenericRepository<>));
    services.AddScoped(typeof(ICustomRepository), typeof(CustomRepository));
    // ..
}

2. Inject and use

public class SampleClass
{   
    // Opt. 1. Inject a UoW for regular DB read and write operations
    // Opt. 2. Inject a UoW-Factory in case you work with multiple databases
    // Opt. 3. Inject a RepositoryFactory to get read-only repositories
    public SampleClass(
        IUnitOfWork unitOfWork, 
        IUnitOfWorkFactory<SampleContext> unitofWorkFactory,
        IRepositoryFactory<SampleContext> repositoryFactory)    
    {
        IRepository<Person> personRepository;   // Register generic repositories manually!
        ICustomRepository customRepository;     // Register custom repositories manually!


        // Opt. 1
        personRepository = unitOfWork.GetRepository<Person>();
        customRepository = unitOfWork.GetRepository<Person, ICustomRepository>();
        // .. do work
        unitOfWork.SaveChanges();


        // Opt. 2
        using var uow = unitofWorkFactory.GetUnitOfWork();
        personRepository = uow.GetRepository<Person>();
        customRepository = uow.GetRepository<Person, ICustomRepository>();
        // .. do work
        uow.SaveChanges();


        // Opt. 3
        personRepository = repositoryFactory.GetRepository<Person>();
        customRepository = repositoryFactory.GetRepository<Person, ICustomRepository>();
        // No SaveChanges available!
    }
}

Getting Started with SI.UnitOfWork.EntityFrameworkCore

1. Install and reference the NuGet package

Install-Package SI.UnitOfWork.EntityFrameworkCore

2. Edit your ConfigureServices() method in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    // ..
    services.AddDbContext<EFContext>(o => o.UseInMemoryDatabase("mem-db");
    services.AddEFUnitOfWork();
    services.AddScoped(typeof(ICustomRepository), typeof(CustomRepository));
    // ..
}

2. Inject and use

public class SampleClass
{
    public SampleClass(IUnitOfWork unitOfWork)
    {
        IRepository<Person> personRepository;   // Generic repositories are automatically registered!
        ICustomRepository customRepository;     // Register custom repositories manually!


        personRepository = unitOfWork.GetRepository<Person>();
        customRepository = unitOfWork.GetRepository<Person, ICustomRepository>();
        // .. do work
        unitOfWork.SaveChanges();
    }
}

Open Source License Acknowledgements and Third-Party Copyrights

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SI.UnitOfWork:

Package Downloads
SI.UnitOfWork.EntityFrameworkCore

EntityFrameworkCore plugin for the lightweight and flexible Repository / UnitOfWork framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 389 2/2/2023
2.0.0 386 11/18/2022
1.0.0 500 6/17/2021
0.1.0 640 10/6/2020