mirror of
https://github.com/bitwarden/server.git
synced 2026-06-01 11:45:20 -05:00
44 lines
1.8 KiB
C#
44 lines
1.8 KiB
C#
using Bit.Core.Entities;
|
|
using Bit.Seeder.Services;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Bit.Seeder.Pipeline;
|
|
|
|
/// <summary>
|
|
/// Convenience extension methods for resolving common services from <see cref="SeederContext.Services"/>.
|
|
/// Minimizes churn in step implementations when transitioning from direct property access to DI.
|
|
/// </summary>
|
|
internal static class SeederContextExtensions
|
|
{
|
|
internal static IPasswordHasher<User> GetPasswordHasher(this SeederContext context) =>
|
|
context.Services.GetRequiredService<IPasswordHasher<User>>();
|
|
|
|
internal static IManglerService GetMangler(this SeederContext context) =>
|
|
context.Services.GetRequiredService<IManglerService>();
|
|
|
|
internal static ISeedReader GetSeedReader(this SeederContext context) =>
|
|
context.Services.GetRequiredService<ISeedReader>();
|
|
|
|
internal static SeederSettings GetSettings(this SeederContext context) =>
|
|
context.Services.GetRequiredService<SeederSettings>();
|
|
|
|
internal static string GetPassword(this SeederContext context) =>
|
|
context.GetSettings().Password ?? Factories.UserSeeder.DefaultPassword;
|
|
|
|
internal static int GetKdfIterations(this SeederContext context) =>
|
|
context.GetSettings().KdfIterations;
|
|
|
|
/// <summary>
|
|
/// Resolves the optional progress reporter. Returns null when no UI is attached.
|
|
/// Callers should null-check before constructing events to keep the no-reporter path allocation-free.
|
|
/// </summary>
|
|
internal static IProgress<SeederProgressEvent>? GetProgress(this SeederContext context) =>
|
|
context.Services.GetService<IProgress<SeederProgressEvent>>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Runtime settings for a seeding operation, registered in DI.
|
|
/// </summary>
|
|
internal sealed record SeederSettings(string? Password = null, int KdfIterations = 5_000);
|