This commit is contained in:
2025-10-27 17:39:18 -04:00
commit 31f723bea4
1579 changed files with 642409 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Channels;
namespace Prefab.Data.Seeder;
public static class Extensions
{
/// <summary>
/// Registers a seeder and its options so it can participate in environment-aware execution.
/// </summary>
/// <typeparam name="TSeeder">Seeder implementation.</typeparam>
/// <param name="services">The host service collection.</param>
/// <param name="runMode">Determines when the seeder is allowed to run.</param>
/// <returns>The provided service collection.</returns>
public static IServiceCollection AddSeeder<TSeeder>(this IServiceCollection services, RunMode runMode = RunMode.RunOnFirstLoadOnly) where TSeeder : class, ISeeder
{
services.AddScoped<ISeeder, TSeeder>();
services.AddScoped<TSeeder>();
services.Configure<SeederOptions<TSeeder>>(opts => opts.RunMode = runMode);
return services;
}
/// <summary>
/// Gets the channel used to queue seeder operations for background execution.
/// </summary>
public static Channel<Func<IServiceProvider, CancellationToken, Task>> Channel { get; }
= System.Threading.Channels.Channel.CreateUnbounded<Func<IServiceProvider, CancellationToken, Task>>();
}