jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11.1k stars 1.18k forks source link

This PR makes the marker interface `INotification` optional. #894

Closed vvdb-architecture closed 1 year ago

vvdb-architecture commented 1 year ago

INotification is an unnecessary constraint. It's absence does not prevent the correct functioning of INotificationHandler/INotificationPublisher.

This avoids the creation of a specific type for each notification type, and allows us to define handlers using value tuples:

public class Entity
{
}

public enum Operation
{
  Create,
  Update
}

public class EntityEventHandler : INotificationHandler<(Entity Entity, Operation Operation)>
{

    public Task Handle((Entity Entity, Operation Operation) notification, CancellationToken cancellationToken)
    {
    }
}

... and then call them using a syntax like:

        mediator.Publish((entity, Operation.Create));
github-actions[bot] commented 1 year ago

This PR is stale because it has been open 28 days with no activity. Remove stale label or comment or this will be closed in 14 days.

jbogard commented 1 year ago

The INotification interface is also there to prevent mistakes. Not publishing requests or sending notifications. I don't want to go back on that just to enable tuples.