Tolitech.Infrastructure.Persistence.EntityFrameworkCore 1.0.0-preview.9

This is a prerelease version of Tolitech.Infrastructure.Persistence.EntityFrameworkCore.
dotnet add package Tolitech.Infrastructure.Persistence.EntityFrameworkCore --version 1.0.0-preview.9
                    
NuGet\Install-Package Tolitech.Infrastructure.Persistence.EntityFrameworkCore -Version 1.0.0-preview.9
                    
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="Tolitech.Infrastructure.Persistence.EntityFrameworkCore" Version="1.0.0-preview.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tolitech.Infrastructure.Persistence.EntityFrameworkCore" Version="1.0.0-preview.9" />
                    
Directory.Packages.props
<PackageReference Include="Tolitech.Infrastructure.Persistence.EntityFrameworkCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tolitech.Infrastructure.Persistence.EntityFrameworkCore --version 1.0.0-preview.9
                    
#r "nuget: Tolitech.Infrastructure.Persistence.EntityFrameworkCore, 1.0.0-preview.9"
                    
#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.
#:package Tolitech.Infrastructure.Persistence.EntityFrameworkCore@1.0.0-preview.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tolitech.Infrastructure.Persistence.EntityFrameworkCore&version=1.0.0-preview.9&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tolitech.Infrastructure.Persistence.EntityFrameworkCore&version=1.0.0-preview.9&prerelease
                    
Install as a Cake Tool

Tolitech.Infrastructure.Persistence.EntityFrameworkCore

A robust .NET library that provides foundational infrastructure for implementing the Repository and Unit of Work patterns with Entity Framework Core. It enables transactional consistency, domain event publishing, and integration event outbox support for modern, scalable applications.

Features

  • Generic Repository Base: Abstract base for repositories, simplifying CRUD operations.
  • Unit of Work Pattern: Transaction management with support for nested transactions.
  • Domain Events: Automatic collection and publishing of domain events after persistence.
  • Integration Events (Outbox Pattern): Reliable persistence of integration events for eventual consistency.
  • Exception Handling: Centralized constraint violation handling.
  • Logging: Transaction and event lifecycle logging.

Installation

Add the NuGet package to your project:

dotnet add package Tolitech.Infrastructure.Persistence.EntityFrameworkCore

Getting Started

1. Implement a Repository

Create a repository by inheriting from Repository<TEntity>:

using Tolitech.Infrastructure.Persistence.EntityFrameworkCore;

public class CustomerRepository : Repository<Customer>
{
    public CustomerRepository(MyDbContext dbContext) : base(dbContext) { }
}

2. Implement a Unit of Work

Create a Unit of Work by inheriting from UnitOfWorkBase:

using Tolitech.Infrastructure.Persistence.EntityFrameworkCore;
using MediatR;
using Microsoft.Extensions.Logging;

public class MyUnitOfWork : UnitOfWorkBase
{
    public MyUnitOfWork(MyDbContext dbContext, IPublisher publisher, ILogger<MyUnitOfWork> logger)
        : base(dbContext, publisher, logger) { }
}

3. Using Transactions and Saving Changes

using (var uow = new MyUnitOfWork(dbContext, publisher, logger))
{
    await uow.BeginTransactionAsync(cancellationToken);
    // ... perform repository operations ...
    await uow.SaveChangesAsync(cancellationToken);
    await uow.CommitAsync(cancellationToken);
}

Or atomically:

await uow.SaveChangesInTransactionAsync(cancellationToken);

4. Domain Events

Entities implementing IAggregate can raise domain events. These are automatically published after SaveChangesAsync if a transaction is open.

5. Integration Events (Outbox)

If using the outbox pattern, pass an IOutbox to the Unit of Work. Integration events are persisted and can be processed later for reliable messaging.

Exception Handling

Constraint violations are handled and wrapped using the ConstraintValidatorManager for consistent error management.

Example: Custom Exception

try
{
    await uow.SaveChangesAsync(cancellationToken);
}
catch (MissingOpenTransactionException ex)
{
    // Handle missing transaction scenario
}

Advanced

  • Isolation Levels: Use BeginTransactionAsync(IsolationLevel, CancellationToken) for custom isolation.
  • Commit or Rollback by Result: Use CommitOrRollbackAsync(Result, CancellationToken) to commit or rollback based on operation result.

Tolitech.Infrastructure.Persistence.EntityFrameworkCore brings transactional consistency, event-driven architecture, and repository abstraction to your .NET applications with Entity Framework Core.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows 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 Tolitech.Infrastructure.Persistence.EntityFrameworkCore:

Package Downloads
Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications

The Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications repository provides a foundational implementation for the Specifications pattern.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.9 11 a day ago
1.0.0-preview.8 105 6 days ago
1.0.0-preview.7 111 19 days ago
1.0.0-preview.6 109 19 days ago
1.0.0-preview.5 157 3 months ago
1.0.0-preview.4 133 3 months ago
1.0.0-preview.3 80 6 months ago
1.0.0-preview.2 71 7 months ago
1.0.0-preview.1 78 7 months ago