Init
This commit is contained in:
29
Prefab/Data/Seeder/Extensions.cs
Normal file
29
Prefab/Data/Seeder/Extensions.cs
Normal 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>>();
|
||||
}
|
||||
Reference in New Issue
Block a user