![]() |
VOOZH | about |
dotnet add package Raycynix.Extensions.Database --version 2.1.0
NuGet\Install-Package Raycynix.Extensions.Database -Version 2.1.0
<PackageReference Include="Raycynix.Extensions.Database" Version="2.1.0" />
<PackageVersion Include="Raycynix.Extensions.Database" Version="2.1.0" />Directory.Packages.props
<PackageReference Include="Raycynix.Extensions.Database" />Project file
paket add Raycynix.Extensions.Database --version 2.1.0
#r "nuget: Raycynix.Extensions.Database, 2.1.0"
#:package Raycynix.Extensions.Database@2.1.0
#addin nuget:?package=Raycynix.Extensions.Database&version=2.1.0Install as a Cake Addin
#tool nuget:?package=Raycynix.Extensions.Database&version=2.1.0Install as a Cake Tool
Core EF Core database infrastructure for Raycynix applications.
AddRaycynixDatabase(...) zero-setup registration with the default DatabaseContextAddRaycynixDatabase<TContext>(...) for custom Raycynix database contextsAddAssembly(...)RaycynixDatabaseContext, GenericConfigurator<T>, and table-name helpersIDatabaseInitializerShared contracts and configuration models live in Raycynix.Extensions.Database.Abstractions.
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(){
"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.
public sealed class AppDatabaseContext : DbContext, IRaycynixDatabaseContext
{
private readonly IDatabaseModelConfigurator _modelConfigurator;
private readonly string _providerName;
public AppDatabaseContext(
DbContextOptions options,
DatabaseConfiguration config,
IDatabaseModelConfigurator modelConfigurator,
IServiceProvider serviceProvider)
: base(options)
{
_modelConfigurator = modelConfigurator;
_providerName = serviceProvider.GetRequiredService<DatabaseProviderDescriptor>().ProviderName;
ChangeTracker.LazyLoadingEnabled = config.EnableLazyLoading;
ChangeTracker.AutoDetectChangesEnabled = config.EnableAutoDetectChanges;
ChangeTracker.QueryTrackingBehavior = config.UseQueryTrackingByDefault
? QueryTrackingBehavior.TrackAll
: QueryTrackingBehavior.NoTracking;
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
_modelConfigurator.Configure(builder, _providerName);
}
public string GetModelCacheKey()
{
return _modelConfigurator.GetModelCacheKey(_providerName);
}
}
builder.Services
.AddRaycynixDatabase<AppDatabaseContext>(builder.Configuration)
.AddPostgreSql();
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 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:
ConfigureEntity(modelBuilder, tableName)DatabaseTableAttribute on the configuratorIf runtime values change the model shape, override GetModelShapeCacheKey():
protected override string? GetModelShapeCacheKey()
{
return options.TableName;
}
Use these packages to run initialization during startup:
Raycynix.Extensions.Database.HostingRaycynix.Extensions.Database.AspNetCoreDatabase tracing and metrics live in Raycynix.Extensions.Database.Observability:
builder.Services
.AddRaycynixDatabase(builder.Configuration)
.AddPostgreSql()
.AddObservability();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 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. |
|
|
Raycynix.Extensions.Database.AspNetCore.Identity
ASP.NET Core Identity EF Core integration for Raycynix.Extensions.Database with default and generic IdentityDbContext registration, custom identity context support, model assembly discovery, provider validation, initialization, and model-cache integration. |
This package is not used by any popular GitHub repositories.
Added explicit model and migrations assembly registration, provider-specific validation hooks, safer DbContext registration, improved configurator dependency diagnostics, and default no-op database observability.