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" />
<PackageReference Include="Netrilo.Infrastructure.Common.Persistence" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Netrilo.Infrastructure.Common.Persistence&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Netrilo.Infrastructure.Common.Persistence
Part of the Netrilo.Infrastructure SDK
📦 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
EfCoreDbOptionsloaded from configuration
- Generic repository pattern (
MongoDB Repository
- Generic repository (
MongoRepository<T>) - Documents must implement
IDocument - CRUD, bulk ops, and LINQ queries
- Configured via
MongoDbSettings
- Generic repository (
Redis Repository
- Generic repository (
IRedisRepository<T>) - Cache and persistence operations
- Configured via
RedisSettings
- Generic repository (
🚀 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 | Versions 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.
-
net9.0
- Dapr.AspNetCore (>= 1.15.4)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 9.0.9)
- Microsoft.EntityFrameworkCore (>= 9.0.9)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.9)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.9)
- MongoDB.Driver (>= 3.4.3)
- Netrilo.Infrastructure.Common.Abstractions (>= 1.0.4)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
- StackExchange.Redis (>= 2.9.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.