NSDatabase.Core 1.1.0

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

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 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.1.0 126 1/6/2026