[backend/database] Fix possible stall / race condition on first startup in EntityFrameworkCoreXmlRepositoryAsync

This commit is contained in:
Laura Hausmann 2024-06-23 00:54:34 +02:00
parent 3bf933782a
commit 259a21b273
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -376,14 +376,14 @@ file sealed class EntityFrameworkCoreXmlRepositoryAsync<TContext> : IXmlReposito
public void StoreElement(XElement element, string friendlyName) public void StoreElement(XElement element, string friendlyName)
{ {
using var scope = _services.CreateScope(); using var scope = _services.CreateAsyncScope();
var requiredService = scope.ServiceProvider.GetRequiredService<TContext>(); using var requiredService = scope.ServiceProvider.GetRequiredService<TContext>();
requiredService.DataProtectionKeys.Add(new DataProtectionKey requiredService.DataProtectionKeys.Add(new DataProtectionKey
{ {
FriendlyName = friendlyName, FriendlyName = friendlyName,
Xml = element.ToString(SaveOptions.DisableFormatting) Xml = element.ToString(SaveOptions.DisableFormatting)
}); });
requiredService.SaveChangesAsync(); requiredService.SaveChangesAsync().Wait();
} }
} }