NSDatabase.Core
1.1.0
dotnet add package NSDatabase.Core --version 1.1.0
NuGet\Install-Package NSDatabase.Core -Version 1.1.0
<PackageReference Include="NSDatabase.Core" Version="1.1.0" />
<PackageVersion Include="NSDatabase.Core" Version="1.1.0" />
<PackageReference Include="NSDatabase.Core" />
paket add NSDatabase.Core --version 1.1.0
#r "nuget: NSDatabase.Core, 1.1.0"
#:package NSDatabase.Core@1.1.0
#addin nuget:?package=NSDatabase.Core&version=1.1.0
#tool nuget:?package=NSDatabase.Core&version=1.1.0
NSDatabase
A lightweight, provider-based, EF Core friendly .NET database management library designed for modern .NET applications. It centralizes configurations, manages connections, migrations, provides automated health checks, structured logging and optional backups. It is designed for developers who want robust defaults, minimal boilerplate and safe automatic EF Core migrations
Features
- Supports multiple EF Core providers (SQL Server, PostgreSQL, MySQL, SQLite, InMemory)
- Centralized DatabaseOptions configuration
- Wires up DBContext automatically
- Supports EF Core migrations out of the box
- Backup and restore services
- Connection pooling and retry policies
- Serilog logging integration (structured, file and console)
- Automated database health-checks
- Lightweight, modular and SOLID compliance
- Dependency Injection friendly service registration
- Fully testable (health-check and logging tests included)
- Seamless integration: Configure once in
appsettings.json, and your DbContext is fully set up
Installation
Install the package via NuGet:
dotnet add package Nanoservice.Database.Core
Install EF Core packages for your chosen provider (example below) :
SQL Server
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
PostgreSQL
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
SQLite
dotnet add package Microsoft.EntityFrameworkCore.SQLite
MySQL
dotnet add package Pomelo.EntityFrameworkCore.MySQL
Configuration
appsettings.json
{
"Database": {
"Provider": "PostgreSql",
"ConnectionString": "Server=localhost;Port=5432;Username=your_database_username;Password=your_password;",
"AutoMigrate": true,
"AllowDestructiveMigrations": true,
"EnableRetryOnFailure": true,
"MaxRetryCount": 5,
"MaxRetryDelaySeconds": 5,
"Backup": {
"Enabled": true,
"BackupDirectory": "backups",
"Compress": true,
"RetentionDays": 30
},
"HealthCheck": {
"Enabled": true,
"Timeout": "00:00:05",
"Tags": [ "db", "ready", "connected", "active" ]
},
"Logging": {
"MinimumLevel": "Information",
"LogFilePath": "logs/db-.log"
}
}
}
- Provider: Database type (PostgreSql, MySQL, SqlServer, Sqlite3).
- AutoMigrate: Apply pending migrations automatically at startup.
- AllowDestructiveMigrations: Only set true if you want table/columns to be dropped or renamed automatically. Defaults to
false.
Usage
Below is a full example of using Nanoservice.Database.Core in ASP.NET Core Web API.
1. Add Your Models
public class Ticket
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
2. Create Your DbContext
public class TicketDbContext : DbContext
{
public TicketDbContext(DbContextOptions<TicketDbContext> options) : base (options) { }
public DbSet<Ticket> Tickets { get; set; }
}
3. Configure NSDatabase.Core in Program.cs
var builder = WebApplication.CreateBuilder(args);
// Register DbContext
builder.Services.AddNSDatabase<TicketDbContext>(builder.Configuration)
.AddDbContext<TicketDbContext>();
// Register service
builder.Services.RegisterService<TicketService>();
app.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = HealthCheckResponseWriter.WriteDetailedResponse
});
That is it. The libray automatically:
- Registers your
DbContext - Applies pending migrations safely
- Registers NSBackupService
- Configures health checks
Running EF Core Migrations
NSDatabase.Core does not replace EF Core migrations - it integrates with them.
1. Add EF Core tools
dotnet tool install --global dotnet-ef
2. Create a migration
If you have new model changes:
dotnet ef migrations add InitialCreate --output-dir Migrations/MySQL(PostgreSql, SQLServer, Sqlite3 etc)
3. Apply the migration
dotnet ef database update --context TicketDbContext
Note: Automatic migrations on startup only apply existing migrations. New model changes must first be created as EF Core migrations.
Your DbContext + models will determine the database schema automatically.
Running Unit Tests
Inside the included test\ folder, run:
dotnet test
Health Check Tests
- Tests the database connectivity behavior
- Tests exception safety
Logging Tests
- Verifies DI logger registration
- Ensures log files are created and written
Health Check Endpoint
If you enable health check feature: GET /health
Response will be either:
- Healthy - Database reachable
- Unhealthy - Connection failed / exception
Logging
Nanoservice.Database.Core uses Serilog internally
Output
- Console
- Rolling log fil:
logs/nanodb-log.txt
Example Log Entry
{
"Timestamp": "2025-12-29-T21:00:00Z",
"Level": "Information",
"Message": "Database connection successfull"
}
Advanced Configuration
options.Pooling.MinPoolSize = 1;
options.Pooling.MaxPoolSize = 100;
options.Retry.MaxRetryCount = 5;
options.Retry.MaxRetryDelaySeconds = 10;
Example Controller
[ApiController]
[Route("api/[controller]")]
public class TicketController : ControllerBase
{
private readonly TicketDbContext _db;
public TicketController(TicketDbContext db) => _db = db
[HttpGet]
public async Task<IActionResult> CreateTicket(Ticket ticket)
{
_db.Tickets.Add(ticket);
await _db.SaveChangesAsync();
return Ok(ticket);
}
}
Summary
NSData gives developers
- Less boilerplate
- Faster setup
- Resilience (health checks and retries)
- Better logging
- Clean EF Core integration
- Easy DI configuration
| 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. |
-
net9.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.Data.Sqlite.Core (>= 9.0.0)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.InMemory (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Sqlite (>= 9.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.1)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.0)
- MySql.Data (>= 9.5.0)
- Npgsql (>= 10.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.1)
- Polly (>= 8.6.5)
- Pomelo.EntityFrameworkCore.MySql (>= 9.0.0)
- Serilog (>= 4.3.0)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Extensions.Logging (>= 10.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
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.1.0 | 126 | 1/6/2026 |