mirror of
https://github.com/bitwarden/server
synced 2026-02-21 03:43:44 +00:00
34 lines
1.3 KiB
C#
34 lines
1.3 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Runtime settings for a seeding operation, registered in DI.
|
|
/// </summary>
|
|
internal sealed record SeederSettings(string? Password = null);
|