Skip to content

Commit

Permalink
Updated Generic publication methods to force using a non-abstract eve…
Browse files Browse the repository at this point in the history
…nt since it's not supported yet
  • Loading branch information
DArdouin committed Dec 27, 2023
1 parent 6a39df0 commit 4796da5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Shared/DomainEventWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public object Unwrap(Type returnType)
}

public static DomainEventWrapper Wrap<T>(T domainEvent)
where T : IDomainEvent
where T : IDomainEvent, new()
{
var domainEventName = DomainEventNameCache.GetName<T>();
var domainEventSchema = DomainEventSchemaCache.GetEventSchema<T>();
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/DomainEventWrapperCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DomainEventWrapperCollection(IEnumerable<DomainEventWrapper> domainEventW
public EventSchema DomainSchema { get; }

public static DomainEventWrapperCollection Create<T>(IEnumerable<T> domainEvents)
where T : IDomainEvent
where T : IDomainEvent, new()
{
var domainEventWrappers = domainEvents.Select(DomainEventWrapper.Wrap).ToArray();
if (domainEventWrappers.Select(x => x.DomainEventName).Distinct().Count() > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class DomainEventNameCache
private static readonly ConcurrentDictionary<Type, string> DomainEventNameTypeMappings = new ConcurrentDictionary<Type, string>();

public static string GetName<T>()
where T : IDomainEvent
where T : IDomainEvent, new()
{
return GetName(typeof(T));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class DomainEventSchemaCache
private static readonly ConcurrentDictionary<Type, EventSchema> DomainEventSchemaTypeMappings = new ConcurrentDictionary<Type, EventSchema>();

public static EventSchema GetEventSchema<T>()
where T : IDomainEvent
where T : IDomainEvent, new()
{
return GetEventSchema(typeof(T));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Workleap.DomainEventPropagation;
public interface IEventPropagationClient
{
Task PublishDomainEventAsync<T>(T domainEvent, CancellationToken cancellationToken)
where T : IDomainEvent;
where T : IDomainEvent, new();

Task PublishDomainEventsAsync<T>(IEnumerable<T> domainEvents, CancellationToken cancellationToken)
where T : IDomainEvent;
where T : IDomainEvent, new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ private static DomainEventsHandlerDelegate BuildPipeline(DomainEventsHandlerDele
}

public Task PublishDomainEventAsync<T>(T domainEvent, CancellationToken cancellationToken)
where T : IDomainEvent
where T : IDomainEvent, new()
=> this.PublishDomainEventsAsync(new[] { domainEvent }, cancellationToken);

public async Task PublishDomainEventsAsync<T>(IEnumerable<T> domainEvents, CancellationToken cancellationToken)
where T : IDomainEvent
where T : IDomainEvent, new()
{
if (domainEvents == null)
{
Expand Down

0 comments on commit 4796da5

Please sign in to comment.