public async Task SeedAsync(KeysManagerContext context, IKeysGeneratorService keysGenerator, ILogger <KeyManagerContextSeed> logger) { var policy = CreatePolicy(logger, nameof(KeyManagerContextSeed)); await policy.ExecuteAsync(async() => { KeysGeneratorConfiguration configuration = new() { Value = keysGenerator.SettingsJson }; if (!context.KeyGeneratorConfigurations.Any()) { await context.KeyGeneratorConfigurations.AddAsync(configuration); await context.SaveChangesAsync(); } else { configuration = context.KeyGeneratorConfigurations.SingleOrDefault(); keysGenerator.SettingsJson = configuration.Value; } if (!context.Keys.Any()) { var keys = keysGenerator.Generate(); var keyEntities = keys.Select(k => new Key(k)); await context.Keys.AddRangeAsync(keyEntities); await context.SaveChangesAsync(); configuration.Value = keysGenerator.SettingsJson; context.KeyGeneratorConfigurations.Update(configuration); await context.SaveChangesAsync(); } }); }
public CreateCitizenCommandHandler(IEgidDbContext context, IFilesDirectoryService directories, ISymmetricCryptographyService cryptographyService, IKeysGeneratorService keys) { _context = context; _directories = directories; _cryptographyService = cryptographyService; _keys = keys; }
public InitializeDbHandler( ICardManagerService cardManager, IKeysGeneratorService citizenKeys, IEgidDbContext context, ISymmetricCryptographyService cryptographyService, IConfiguration config) { _citizenKeys = citizenKeys; _context = context; _cryptographyService = cryptographyService; _config = config; _cardManager = cardManager; }