Modrich.Persistence
0.1.0
dotnet add package Modrich.Persistence --version 0.1.0
NuGet\Install-Package Modrich.Persistence -Version 0.1.0
<PackageReference Include="Modrich.Persistence" Version="0.1.0" />
<PackageVersion Include="Modrich.Persistence" Version="0.1.0" />
<PackageReference Include="Modrich.Persistence" />
paket add Modrich.Persistence --version 0.1.0
#r "nuget: Modrich.Persistence, 0.1.0"
#:package Modrich.Persistence@0.1.0
#addin nuget:?package=Modrich.Persistence&version=0.1.0
#tool nuget:?package=Modrich.Persistence&version=0.1.0
Modrich.Persistence
Generic migrate-and-seed pipeline for Modrich modules on .NET 10. Each module owns its DbContext and registers IModuleMigrator + IModuleSeeder; this package runs them in order.
What's in the box
ModuleSeederRunner.RunAsync(IServiceProvider)- Creates a DI scope.
- Resolves every
IModuleMigratorand invokesMigrateAsyncin ascendingOrder. - Resolves every
IModuleSeederand invokesSeedAsyncin ascendingOrder.
That's the whole package. The contracts live in Modrich.Abstractions.
Install
dotnet add package Modrich.Persistence
Usage — module-side
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Modrich.Modules;
public sealed class OrdersMigrator : IModuleMigrator
{
public int Order => 100;
public async Task MigrateAsync(IServiceProvider services)
{
var db = services.GetRequiredService<OrdersDbContext>();
await db.Database.MigrateAsync();
}
}
public sealed class OrdersSeeder : IModuleSeeder
{
public int Order => 100;
public async Task SeedAsync(IServiceProvider services)
{
var db = services.GetRequiredService<OrdersDbContext>();
if (await db.OrderStatuses.AnyAsync()) return;
db.OrderStatuses.AddRange(new("New"), new("Paid"), new("Shipped"));
await db.SaveChangesAsync();
}
}
public sealed class OrdersApiModule : IApiModule
{
public string Name => "Orders";
public void RegisterApiDependencies(IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<OrdersDbContext>(o =>
o.UseSqlServer(configuration.GetConnectionString("Default")));
services.AddScoped<IModuleMigrator, OrdersMigrator>();
services.AddScoped<IModuleSeeder, OrdersSeeder>();
}
}
Usage — host-side
using Modrich.Persistence;
var app = builder.Build();
await ModuleSeederRunner.RunAsync(app.Services);
app.Run();
Modules run in the order they assign — pick conservative numbers (10, 100, 200) so later modules can slot between earlier ones. All migrators complete before any seeder runs, so a seeder in module A can safely read tables created by module B.
Related packages
Modrich.Abstractions—IModuleMigrator,IModuleSeeder.Modrich.Modularity— discovers and registers your module's services so they end up in the DI container the runner enumerates.
Versioning
Strict semver. EnablePackageValidation is on.
License
MIT.
| Product | Versions 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. |
-
net10.0
- Modrich.Modularity (>= 0.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.