Command.Seeder 1.0.2

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

🌱 Seeder Command Dispatcher

A lightweight database seeding framework for .NET, inspired by Laravel’s db:seed command. Easily discover and run all seeders dynamically in ASP.NET Core or Console projects. For any problems or new ideas please email me at: hossein.holy.shrine@gmail.com

✨ Features

  • πŸš€ Command-style seeding dotnet run db:seed
  • πŸ” Auto-discovery of all ISeeder implementations
  • ⚑ Run one or multiple seeders at once
  • πŸ›  Works with any EF Core DbContext
  • 🌐 Works in Web APIs and Console Apps
  • πŸ”„ Centralized configuration for flexible DbContext swapping
  • πŸ“₯ Installation

πŸš€ Quick Start 1️⃣ Define a Seeder

using YourProject.Seeders;
using Microsoft.EntityFrameworkCore;
using Seeder.Seeders;

public class DegreeSeeder : ISeeder
{
    private readonly MyDbContext _db;
    public DegreeSeeder(MyDbContext db) => _db = db;

    public async Task SeedAsync()
    {
        var degrees = new[]
        {
            new Degree { Name = "low" },
            new Degree { Name = "medium" },
            new Degree { Name = "hight" },
        };

        _db.Degrees.AddRange(degrees);
        await _db.SaveChangesAsync(cancellationToken);
    }
}

2️⃣ Register Seeders In ASP.NET Core Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))
);

// Register all seeders
builder.Services.AddAllSeeders();

var app = builder.Build();

// Attach seeder dispatcher
SeederCommandDispatcher.ConfigureWithDbContext<MyDbContext>(app.Services);

if (await SeederCommandDispatcher.TryExecuteCommandAsync(args))
{
    return; // Run seeder and exit
}

app.Run();

In Console App:

using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;

using var host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((context, services) =>
    {
        services.AddDbContext<MyDbContext>(options =>
            options.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection")));
        services.AddAllSeeders();
    })
    .Build();

SeederCommandDispatcher.ConfigureWithDbContext<MyDbContext>(host.Services);
if (await SeederCommandDispatcher.TryExecuteCommandAsync(args)) return;

3️⃣ Run Seeders

Run all seeders:

dotnet run db:seed

or

dotnet run db:seed all

Run a specific seeder:

dotnet run db:seed DegreeSeeder

Run multiple seeders:

dotnet run db:seed DegreeSeeder UserSeeder RoleSeeder

πŸ“Š Example Output

> dotnet run db:seed DegreeSeeder
[INFO] Running DegreeSeeder...
[OK]   Inserted 3 degrees

πŸ“– Requirements

  • .NET 9.0 or higher
  • EF Core (SQL Server, PostgreSQL, MySQL, SQLite supported)

πŸ“ License This project is licensed under the MIT License.

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.0.2 272 8/26/2025
1.0.1 182 8/20/2025
1.0.0 174 8/20/2025