Nabs.Launchpad.Core.SeedData
9.0.146
Prefix Reserved
dotnet add package Nabs.Launchpad.Core.SeedData --version 9.0.146
NuGet\Install-Package Nabs.Launchpad.Core.SeedData -Version 9.0.146
<PackageReference Include="Nabs.Launchpad.Core.SeedData" Version="9.0.146" />
<PackageVersion Include="Nabs.Launchpad.Core.SeedData" Version="9.0.146" />
<PackageReference Include="Nabs.Launchpad.Core.SeedData" />
paket add Nabs.Launchpad.Core.SeedData --version 9.0.146
#r "nuget: Nabs.Launchpad.Core.SeedData, 9.0.146"
#:package Nabs.Launchpad.Core.SeedData@9.0.146
#addin nuget:?package=Nabs.Launchpad.Core.SeedData&version=9.0.146
#tool nuget:?package=Nabs.Launchpad.Core.SeedData&version=9.0.146
Nabs Launchpad Core Seed Data Library
A .NET 9 library providing interfaces and abstractions for database seeding and migration operations in the Nabs Launchpad framework.
Overview
The Nabs.Launchpad.Core.SeedData
library defines core interfaces for managing database initialization tasks including:
- Database schema migrations
- Test data generation and seeding
- Development environment data setup
This library provides the contracts that implementations can use to handle database setup operations in a consistent manner across the Launchpad platform.
Features
- Migration Processing: Interface for handling database schema migrations
- Seed Data Processing: Interface for populating databases with initial or test data
- Async Support: All operations support cancellation tokens and async patterns
- Framework Integration: Designed to work seamlessly with dependency injection and hosted services
Core Interfaces
ISeedDataProcessor
Defines a contract for processing seed data operations:
public interface ISeedDataProcessor
{
Task ProcessAsync(CancellationToken stoppingToken);
}
Use this interface to implement classes that populate your database with:
- Initial application data
- Test data for development environments
- Sample data for demonstrations
IMigrationProcessor
Defines a contract for handling database migrations:
public interface IMigrationProcessor
{
Task MigrateAsync(CancellationToken stoppingToken);
}
Use this interface to implement classes that:
- Apply database schema changes
- Execute migration scripts
- Ensure database schema is up-to-date
Dependencies
- .NET 9: Target framework
- Bogus: Fake data generation library for creating realistic test data
Usage Examples
Implementing ISeedDataProcessor
public class UserSeedDataProcessor : ISeedDataProcessor
{
private readonly IUserRepository _userRepository;
private readonly Faker<User> _userFaker;
public UserSeedDataProcessor(IUserRepository userRepository)
{
_userRepository = userRepository;
_userFaker = new Faker<User>()
.RuleFor(u => u.FirstName, f => f.Name.FirstName())
.RuleFor(u => u.LastName, f => f.Name.LastName())
.RuleFor(u => u.Email, f => f.Internet.Email());
}
public async Task ProcessAsync(CancellationToken stoppingToken)
{
if (await _userRepository.AnyAsync(stoppingToken))
return; // Data already exists
var users = _userFaker.Generate(100);
await _userRepository.AddRangeAsync(users, stoppingToken);
}
}
Implementing IMigrationProcessor
public class DatabaseMigrationProcessor : IMigrationProcessor
{
private readonly ApplicationDbContext _context;
public DatabaseMigrationProcessor(ApplicationDbContext context)
{
_context = context;
}
public async Task MigrateAsync(CancellationToken stoppingToken)
{
await _context.Database.MigrateAsync(stoppingToken);
}
}
Dependency Injection Registration
services.AddScoped<ISeedDataProcessor, UserSeedDataProcessor>();
services.AddScoped<IMigrationProcessor, DatabaseMigrationProcessor>();
Using in Hosted Service
public class DatabaseInitializationService : IHostedService
{
private readonly IMigrationProcessor _migrationProcessor;
private readonly ISeedDataProcessor _seedDataProcessor;
public DatabaseInitializationService(
IMigrationProcessor migrationProcessor,
ISeedDataProcessor seedDataProcessor)
{
_migrationProcessor = migrationProcessor;
_seedDataProcessor = seedDataProcessor;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
await _migrationProcessor.MigrateAsync(cancellationToken);
await _seedDataProcessor.ProcessAsync(cancellationToken);
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
Integration with Launchpad
This library is part of the larger Nabs Launchpad framework and integrates with:
- Core.Testing.Silos: Provides test data for Orleans silo testing
- Core.Persistence: Works with Entity Framework contexts for data operations
- Core.Context: Integrates with application database contexts
Best Practices
- Environment-Specific Data: Only seed data appropriate for the current environment
- Idempotent Operations: Ensure seed operations can be run multiple times safely
- Performance Considerations: Use bulk operations for large datasets
- Error Handling: Implement proper error handling and logging
- Cancellation Support: Always respect cancellation tokens for graceful shutdowns
Testing
The library includes comprehensive unit tests in the Launchpad.Core.SeedData.UnitTests
project to ensure reliability and correctness of the interfaces and any shared implementations.
Contributing
This library follows the Nabs Launchpad coding standards:
- Use C# 13 features and latest language constructs
- Follow nullable reference types conventions
- Implement proper async/await patterns
- Include comprehensive unit tests
License
Copyright � Net Advantage Business Solutions
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
- Bogus (>= 35.6.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Nabs.Launchpad.Core.SeedData:
Package | Downloads |
---|---|
Nabs.Launchpad.Core.Testing.Silos
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.