Foundatio.Repositories 7.18.0-beta2

Prefix Reserved
This is a prerelease version of Foundatio.Repositories.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Foundatio.Repositories --version 7.18.0-beta2
                    
NuGet\Install-Package Foundatio.Repositories -Version 7.18.0-beta2
                    
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="Foundatio.Repositories" Version="7.18.0-beta2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Foundatio.Repositories" Version="7.18.0-beta2" />
                    
Directory.Packages.props
<PackageReference Include="Foundatio.Repositories" />
                    
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 Foundatio.Repositories --version 7.18.0-beta2
                    
#r "nuget: Foundatio.Repositories, 7.18.0-beta2"
                    
#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 Foundatio.Repositories@7.18.0-beta2
                    
#: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=Foundatio.Repositories&version=7.18.0-beta2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Foundatio.Repositories&version=7.18.0-beta2&prerelease
                    
Install as a Cake Tool

FoundatioFoundatio

Build status NuGet Version feedz.io Discord

Foundatio.Repositories

A production-grade repository pattern library for .NET with Elasticsearch implementation. Built on Foundatio building blocks, it provides a clean abstraction over data access with powerful features like caching, messaging, soft deletes, and versioning.

📖 Full Documentation

Installation

dotnet add package Foundatio.Repositories.Elasticsearch

Quick Start

1. Define Your Entity

using Foundatio.Repositories.Models;

public class Employee : IIdentity, IHaveDates, ISupportSoftDeletes
{
    public string Id { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public int Age { get; set; }
    public DateTime CreatedUtc { get; set; }
    public DateTime UpdatedUtc { get; set; }
    public bool IsDeleted { get; set; }
}

2. Create Index Configuration

using Foundatio.Repositories.Elasticsearch.Configuration;

public sealed class EmployeeIndex : VersionedIndex<Employee>
{
    public EmployeeIndex(IElasticConfiguration configuration) 
        : base(configuration, "employees", version: 1) { }

    public override TypeMappingDescriptor<Employee> ConfigureIndexMapping(
        TypeMappingDescriptor<Employee> map)
    {
        return map
            .Dynamic(false)
            .Properties(p => p
                .SetupDefaults()
                .Text(f => f.Name(e => e.Name).AddKeywordAndSortFields())
                .Text(f => f.Name(e => e.Email).AddKeywordAndSortFields())
                .Number(f => f.Name(e => e.Age).Type(NumberType.Integer))
            );
    }
}

3. Create Repository

using Foundatio.Repositories;
using Foundatio.Repositories.Elasticsearch;

public interface IEmployeeRepository : ISearchableRepository<Employee> { }

public class EmployeeRepository : ElasticRepositoryBase<Employee>, IEmployeeRepository
{
    public EmployeeRepository(MyElasticConfiguration configuration) 
        : base(configuration.Employees) { }
}

4. Use the Repository

// Add
var employee = await repository.AddAsync(new Employee 
{ 
    Name = "John Doe", 
    Email = "john@example.com",
    Age = 30 
});

// Query
var results = await repository.FindAsync(q => q
    .FilterExpression("age:>=25")
    .SortExpression("name"));

// Update
employee.Age = 31;
await repository.SaveAsync(employee);

// Soft delete
employee.IsDeleted = true;
await repository.SaveAsync(employee);

// Hard delete
await repository.RemoveAsync(employee);

Features

Repository Pattern

  • IReadOnlyRepository<T> - Read operations (Get, Find, Count, Exists)
  • IRepository<T> - Write operations (Add, Save, Remove, Patch)
  • ISearchableRepository<T> - Dynamic querying with filters, sorting, and aggregations

Patch Operations

  • JSON Patch - RFC 6902 compliant patch operations
  • Partial Patch - Update specific fields without loading the full document
  • Script Patch - Elasticsearch Painless scripts for complex updates
  • Bulk Patching - Apply patches to multiple documents via query

Caching

  • Built-in distributed caching with automatic invalidation
  • Real-time cache consistency via message bus
  • Configurable cache expiration and custom cache keys

Message Bus

  • Entity change notifications (EntityChanged messages)
  • Real-time updates for event-driven architectures
  • Soft delete transition detection (ChangeType.Removed)

Soft Deletes

  • Automatic query filtering based on IsDeleted
  • Three query modes: ActiveOnly, DeletedOnly, All
  • Restore capability for soft-deleted documents

Document Versioning

  • Optimistic concurrency control
  • Automatic version conflict detection
  • Retry patterns for conflict resolution

Index Management

  • Index<T> - Basic index configuration
  • VersionedIndex<T> - Schema versioning with migrations
  • DailyIndex<T> - Time-series with daily partitioning
  • MonthlyIndex<T> - Time-series with monthly partitioning

Event System

  • DocumentsAdding / DocumentsAdded
  • DocumentsSaving / DocumentsSaved
  • DocumentsRemoving / DocumentsRemoved
  • DocumentsChanging / DocumentsChanged
  • BeforeQuery - Query interception
  • BeforePublishEntityChanged - Notification interception

Additional Features

  • Document validation with custom validators
  • Migrations for data schema evolution
  • Jobs for index maintenance, snapshots, and cleanup
  • Custom fields for tenant-specific data
  • Parent-child document relationships
  • Aggregations and analytics

Documentation

Visit the full documentation for detailed guides:

Sample Application

See the sample Blazor application for a complete working example.

Contributing

We welcome contributions! Please see our contributing guidelines for details.

License

Licensed under the Apache License, Version 2.0. See LICENSE.txt for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  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 is compatible.  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 Foundatio.Repositories:

Package Downloads
Foundatio.Repositories.Elasticsearch

Generic Repository implementations for Elasticsearch.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.18.0-beta3 56 2/14/2026
7.18.0-beta2 28 2/14/2026
7.18.0-beta1 293 1/12/2026
7.17.17 5,893 8/21/2025
7.17.16 318 8/20/2025
7.17.15 500 5/9/2025
7.17.14 826 1/31/2025
7.17.13 747 11/26/2024
7.17.12 901 9/28/2024
7.17.11 457 8/31/2024
7.17.10 217 8/31/2024
7.17.9 8,825 5/20/2024
7.17.8 5,030 3/27/2024
7.17.7 3,560 1/5/2024
7.17.6 1,257 10/26/2023
7.17.5 1,834 8/2/2023
7.17.4 1,545 6/23/2023
7.17.3 8,978 1/1/2023
7.17.2 6,814 5/18/2022
7.17.1 3,640 3/10/2022
Loading failed