Netrilo.Infrastructure.Common.Persistence 1.0.4

dotnet add package Netrilo.Infrastructure.Common.Persistence --version 1.0.4
                    
NuGet\Install-Package Netrilo.Infrastructure.Common.Persistence -Version 1.0.4
                    
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="Netrilo.Infrastructure.Common.Persistence" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Netrilo.Infrastructure.Common.Persistence" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Netrilo.Infrastructure.Common.Persistence" />
                    
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 Netrilo.Infrastructure.Common.Persistence --version 1.0.4
                    
#r "nuget: Netrilo.Infrastructure.Common.Persistence, 1.0.4"
                    
#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 Netrilo.Infrastructure.Common.Persistence@1.0.4
                    
#: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=Netrilo.Infrastructure.Common.Persistence&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Netrilo.Infrastructure.Common.Persistence&version=1.0.4
                    
Install as a Cake Tool

Netrilo.Infrastructure.Common.Persistence

Part of the Netrilo.Infrastructure SDK

📦 NuGet

NuGet

📖 Description

A modular persistence library for .NET 8/9 applications.
Provides a unified repository pattern and configuration utilities for working with SQL (EF Core: PostgreSQL & SQL Server), MongoDB, and Redis in a clean and extensible way.


✨ Features

  • Entity Framework Core Repository

    • Generic repository pattern (EfCoreRepository<T>)
    • Async CRUD operations
    • Owned entity change detection (HasChangedOwnedEntities)
    • Built-in provider support:
      • PostgreSQL
      • SQL Server
    • EF Core registration via EfCoreDbOptions loaded from configuration
  • MongoDB Repository

    • Generic repository (MongoRepository<T>)
    • Documents must implement IDocument
    • CRUD, bulk ops, and LINQ queries
    • Configured via MongoDbSettings
  • Redis Repository

    • Generic repository (IRedisRepository<T>)
    • Cache and persistence operations
    • Configured via RedisSettings

🚀 Usage

1. EF Core Setup

appsettings.json (PostgreSQL)
{
  "EfCore": {
    "DatabaseType": "Postgres",
    "ConnectionString": "Host=localhost;Database=MyAppDb;Username=myuser;Password=mypassword"
  }
}
appsettings.json (SQL Server)
{
  "EfCore": {
    "DatabaseType": "SqlServer",
    "ConnectionString": "Server=.;Database=MyAppDb;Trusted_Connection=True;TrustServerCertificate=True;"
  }
}
Program.cs
using Netrilo.Infrastructure.Common.Persistence.Sql.EfCore;

builder.Services.AddEfCore<MyDbContext>(builder.Configuration.GetSection("EfCore"));

// Later in Program.cs
app.UseEfCore();

2. EF Core Repository Example

public class UserService
{
    private readonly IEfCoreRepository<User> _repository;

    public UserService(IEfCoreRepository<User> repository)
    {
        _repository = repository;
    }

    public async Task<User?> GetUserAsync(Guid id) =>
        await _repository.GetByIdAsync(id);

    public async Task AddUserAsync(User user)
    {
        await _repository.AddAsync(user);
        await _repository.SaveChangesAsync();
    }
}

3. MongoDB Setup

appsettings.json
{
  "MongoDbSettings": {
    "ConnectionString": "mongodb://localhost:27017",
    "DatabaseName": "MyDatabase"
  }
}
Program.cs
using Netrilo.Infrastructure.Common.Persistence.NoSql.Mongo;

builder.Services.AddMongoDb(builder.Configuration.GetSection("MongoDbSettings"));
Product Document
using Netrilo.Infrastructure.Common.Persistence.NoSql.Mongo.Documents;

public class Product : IDocument
{
    public Guid Id { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; }

    // Custom fields
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
}
Service
public class ProductService
{
    private readonly IMongoRepository<Product> _repository;

    public ProductService(IMongoRepository<Product> repository)
    {
        _repository = repository;
    }

    public async Task AddProduct(Product product) =>
        await _repository.InsertAsync(product);

    public async Task<List<Product>> GetAllProducts() =>
        await _repository.FilterBy(_ => true).ToListAsync();
}

4. Redis Setup

appsettings.json
{
  "RedisSettings": {
    "ConnectionString": "localhost:6379",
    "DefaultDatabase": 0
  }
}
Program.cs
using Netrilo.Infrastructure.Common.Persistence.NoSql.Redis;

builder.Services.AddRedis(builder.Configuration.GetSection("RedisSettings"));
Usage
public class CacheService
{
    private readonly IRedisRepository<string> _cache;

    public CacheService(IRedisRepository<string> cache)
    {
        _cache = cache;
    }

    public async Task CacheValue(string key, string value) =>
        await _cache.SetAsync(key, value);

    public async Task<string?> GetValue(string key) =>
        await _cache.GetAsync(key);
}

📄 License

MIT License

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 315 9/15/2025
1.0.3 274 9/15/2025
1.0.2 115 9/12/2025
1.0.1 130 9/12/2025