Raycynix.Extensions.Database 2.0.0

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

Raycynix.Extensions.Database

Core EF Core database infrastructure for Raycynix applications.

What It Provides

  • AddRaycynixDatabase(...) zero-setup registration with the default DatabaseContext
  • AddRaycynixDatabase<TContext>(...) for custom Raycynix database contexts
  • marker and explicit assembly overloads for model configurators and EF Core migrations
  • model assembly discovery through AddAssembly(...)
  • RaycynixDatabaseContext, DatabaseContext, GenericConfigurator<T>, and table-name helpers
  • provider selection through provider packages such as PostgreSQL, SQL Server, MySQL, or SQLite
  • startup initialization through IDatabaseInitializer
  • default no-op database observability

Shared contracts and configuration models live in Raycynix.Extensions.Database.Abstractions.

Basic Usage

For simple applications, call AddRaycynixDatabase(...) and one provider. The application entry assembly is registered automatically for configurator discovery and migrations.

builder.Services
    .AddRaycynixDatabase(builder.Configuration, options =>
    {
        options.UseMigrations = true;
        options.EnsureCreated = false;
    })
    .AddPostgreSql();

Exactly one provider must be registered:

  • AddPostgreSql()
  • AddMsSql()
  • AddMySql()
  • AddSqlite()

Configuration

{
  "DatabaseConfiguration": {
    "ConnectionString": "Host=localhost;Port=5432;Database=app;Username=app;Password=secret",
    "UseMigrations": true,
    "EnsureCreated": false,
    "EnableSeed": true,
    "EnableLazyLoading": false,
    "EnableAutoDetectChanges": true,
    "UseQueryTrackingByDefault": true,
    "RetryCount": 5,
    "RetryDelaySeconds": 10
  }
}

Provider-specific settings are nested under DatabaseConfiguration:

{
  "DatabaseConfiguration": {
    "PostgreSqlConfiguration": {
      "Pooling": true,
      "MinimumPoolSize": 5,
      "MaximumPoolSize": 50,
      "CommandTimeoutSeconds": 30,
      "IncludeErrorDetail": false
    }
  }
}

Provider packages validate their own structured connection requirements before building connection strings.

Custom Contexts

public sealed class AppDatabaseContext : RaycynixDatabaseContext
{
    public AppDatabaseContext(
        DbContextOptions<AppDatabaseContext> options,
        DatabaseConfiguration config,
        IDatabaseModelAssemblyRegistry modelAssemblyRegistry,
        IDatabaseObservability observability,
        ILogger<RaycynixDatabaseContext> logger,
        IServiceProvider serviceProvider)
        : base(options, config, modelAssemblyRegistry, observability, logger, serviceProvider)
    {
    }
}

builder.Services
    .AddRaycynixDatabase<AppDatabaseContext>(builder.Configuration)
    .AddPostgreSql();

Assembly Registration

The default registration scans the application entry assembly. For modular applications, register model assemblies explicitly:

builder.Services
    .AddRaycynixDatabase(builder.Configuration, registerCallerAssembly: false)
    .AddAssembly<IdentityDatabaseMarker>()
    .AddAssembly<AuditDatabaseMarker>()
    .AddPostgreSql();

When model configurators and migrations live in different assemblies, use marker overloads:

builder.Services
    .AddRaycynixDatabase<DatabaseContext, AppModelMarker, AppMigrationsMarker>(builder.Configuration)
    .AddPostgreSql();

or explicit assemblies:

builder.Services
    .AddRaycynixDatabase<DatabaseContext>(
        builder.Configuration,
        migrationsAssembly: typeof(AppMigrationsMarker).Assembly,
        modelAssembly: typeof(AppModelMarker).Assembly)
    .AddPostgreSql();

If AddRaycynixDatabase is called more than once with the same context, only the first call may configure DatabaseConfiguration. Later calls can add assemblies but cannot pass another setup callback.

Configurators

Configurators contribute EF Core model configuration to the shared context:

[DatabaseTable("orders")]
public sealed class OrderConfigurator : GenericConfigurator<Order>
{
    public override Type[] DependsOn => [];

    public override void Configure(ModelBuilder modelBuilder)
    {
        var entity = ConfigureEntity(modelBuilder);
        entity.HasKey(static order => order.Id);
    }
}

Table names are resolved in this order:

  1. explicit runtime name passed to ConfigureEntity(modelBuilder, tableName)
  2. DatabaseTableAttribute on the configurator
  3. entity type name

If runtime values change the model shape, override GetModelShapeCacheKey():

protected override string? GetModelShapeCacheKey()
{
    return options.TableName;
}

Startup Initialization

Use these packages to run initialization during startup:

  • Raycynix.Extensions.Database.Hosting
  • Raycynix.Extensions.Database.AspNetCore

Observability

Database tracing and metrics live in Raycynix.Extensions.Database.Observability:

builder.Services
    .AddRaycynixDatabase(builder.Configuration)
    .AddPostgreSql()
    .AddObservability();
Product Compatible and additional computed target framework versions.
.NET 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 Raycynix.Extensions.Database:

Package Downloads
Raycynix.Extensions.Messaging.Database

Database-backed messaging inbox and outbox persistence with ambient unit-of-work support, optimistic concurrency leasing, retention cleanup, and configuration-based setup on the shared Raycynix DatabaseContext.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 42 6/1/2026
1.0.1 157 4/20/2026
1.0.0 181 4/8/2026
0.4.0 122 4/8/2026

Added explicit model and migrations assembly registration, provider-specific validation hooks, safer DbContext registration, improved configurator dependency diagnostics, and default no-op database observability.