1
0
mirror of https://github.com/bitwarden/server synced 2025-12-17 08:43:27 +00:00

Refactor recipies into scenes

This commit is contained in:
Hinton
2025-10-17 11:47:19 -04:00
parent f6fe7a9316
commit fd41332e4c
8 changed files with 120 additions and 108 deletions

View File

@@ -0,0 +1,29 @@
using System.Reflection;
using Bit.Seeder;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Bit.SeederApi.Extensions;
public static class ServiceCollectionExtensions
{
/// <summary>
/// Dynamically registers all scene types that implement IScene<TRequest> from the Seeder assembly.
/// Scenes are registered as keyed scoped services using their class name as the key.
/// </summary>
public static IServiceCollection AddScenes(this IServiceCollection services)
{
var seederAssembly = Assembly.Load("Seeder");
var sceneTypes = seederAssembly.GetTypes()
.Where(t => t is { IsClass: true, IsAbstract: false } &&
t.GetInterfaces().Any(i => i.IsGenericType &&
i.GetGenericTypeDefinition().Name == "IScene`1"));
foreach (var sceneType in sceneTypes)
{
services.TryAddScoped(sceneType);
services.TryAddKeyedScoped(typeof(IScene), sceneType.Name, (sp, key) => sp.GetRequiredService(sceneType));
}
return services;
}
}