[backend/database] Fix possible stall / race condition on first startup in EntityFrameworkCoreXmlRepositoryAsync
This commit is contained in:
parent
3bf933782a
commit
259a21b273
1 changed files with 4 additions and 4 deletions
|
@ -161,7 +161,7 @@ public static class ServiceExtensions
|
|||
{
|
||||
var config = configuration.GetSection("Database").Get<Config.DatabaseSection>() ??
|
||||
throw new Exception("Failed to initialize database: Failed to load configuration");
|
||||
|
||||
|
||||
var dataSource = DatabaseContext.GetDataSource(config);
|
||||
services.AddDbContext<DatabaseContext>(options => { DatabaseContext.Configure(options, dataSource, config); });
|
||||
services.AddKeyedDatabaseContext<DatabaseContext>("cache");
|
||||
|
@ -376,14 +376,14 @@ file sealed class EntityFrameworkCoreXmlRepositoryAsync<TContext> : IXmlReposito
|
|||
|
||||
public void StoreElement(XElement element, string friendlyName)
|
||||
{
|
||||
using var scope = _services.CreateScope();
|
||||
var requiredService = scope.ServiceProvider.GetRequiredService<TContext>();
|
||||
using var scope = _services.CreateAsyncScope();
|
||||
using var requiredService = scope.ServiceProvider.GetRequiredService<TContext>();
|
||||
requiredService.DataProtectionKeys.Add(new DataProtectionKey
|
||||
{
|
||||
FriendlyName = friendlyName,
|
||||
Xml = element.ToString(SaveOptions.DisableFormatting)
|
||||
});
|
||||
requiredService.SaveChangesAsync();
|
||||
requiredService.SaveChangesAsync().Wait();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue