Skip to content

Commit

Permalink
Unlock init
Browse files Browse the repository at this point in the history
  • Loading branch information
MagnusSandgren committed Oct 16, 2024
1 parent 461f060 commit 085ecae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/Digdir.Domain.Dialogporten.Domain/DomainExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Digdir.Domain.Dialogporten.Domain.Common.EventPublisher;

namespace Digdir.Domain.Dialogporten.Domain;

public static class DomainExtensions
{
public static IEnumerable<Type> GetDomainEventTypes()
=> DomainAssemblyMarker.Assembly
.GetTypes()
.Where(x => !x.IsAbstract && !x.IsInterface && !x.IsGenericType)
.Where(x => x.IsAssignableTo(typeof(IDomainEvent)));
}
11 changes: 0 additions & 11 deletions src/Digdir.Domain.Dialogporten.Domain/MediaTypes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Digdir.Domain.Dialogporten.Domain.Common.EventPublisher;

namespace Digdir.Domain.Dialogporten.Domain;

public static class MediaTypes
Expand All @@ -12,12 +10,3 @@ public static class MediaTypes
public const string Markdown = "text/markdown";
public const string PlainText = "text/plain";
}

public static class DomainExtensions
{
public static IEnumerable<Type> GetDomainEventTypes()
=> DomainAssemblyMarker.Assembly
.GetTypes()
.Where(x => !x.IsAbstract && !x.IsInterface && !x.IsGenericType)
.Where(x => x.IsAssignableTo(typeof(IDomainEvent)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,26 @@ public async ValueTask DisposeAsync()
internal async Task Initialize(bool isFirstAttempt = false, CancellationToken cancellationToken = default)
{
await _initializeLock.WaitAsync(cancellationToken);
if (_serviceScope is not null)

try
{
return;
if (_serviceScope is not null)
{
throw new InvalidOperationException("Transaction already started.");
}

_serviceScope = _serviceScopeFactory.CreateScope();
_db = _serviceScope.ServiceProvider.GetRequiredService<DialogDbContext>();
if (!isFirstAttempt)
{
await _db.NotificationAcknowledgements
.Where(x => x.EventId == _eventId)
.LoadAsync(cancellationToken);
}
}

_serviceScope = _serviceScopeFactory.CreateScope();
_db = _serviceScope.ServiceProvider.GetRequiredService<DialogDbContext>();
if (!isFirstAttempt)
finally
{
await _db.NotificationAcknowledgements
.Where(x => x.EventId == _eventId)
.LoadAsync(cancellationToken);
_initializeLock.Release();
}
}

Expand Down

0 comments on commit 085ecae

Please sign in to comment.