hopefully not a horribly foolish refactoring
This commit is contained in:
parent
59d660165f
commit
1ecaf64dea
82 changed files with 782 additions and 398 deletions
29
Femto.Common/Infrastructure/Outbox/Outbox.cs
Normal file
29
Femto.Common/Infrastructure/Outbox/Outbox.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using Femto.Common.Attributes;
|
||||
using Femto.Common.Integration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Femto.Common.Infrastructure.Outbox;
|
||||
|
||||
public class Outbox<TContext>(TContext context, IOutboxMessageMapping mapping) where TContext : IOutboxContext
|
||||
{
|
||||
public async Task AddMessage<TMessage>(
|
||||
Guid aggregateId,
|
||||
TMessage message,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
where TMessage : IIntegrationEvent
|
||||
{
|
||||
var eventName = mapping.GetEventName(typeof(TMessage));
|
||||
if (eventName is null)
|
||||
throw new InvalidOperationException(
|
||||
$"{typeof(TMessage).Name} does not have EventType attribute"
|
||||
);
|
||||
|
||||
await context.Outbox.AddAsync(
|
||||
new(message.EventId, aggregateId, eventName, JsonSerializer.Serialize(message)),
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue