TL;DR How can I adapt an existing set of events/notifications and related handlers so they can be used by MediatR without having to implement extra handlers and notifications for each existing type?
Long version: We currently have a system for dispatching events, where we use a bus implementation to do the actual transport.
I am currently experimenting with an In-process variant.
So similar to MediatR's INotification we have a marker interface IEvent
Likewise similar to the INotificationHandler<in INotification> of MediatR we have an IEventHandler<in IEvent>
We use Autofac to register our EventHandlers, and then we have some reflection stuff going on when actually consuming things from the bus.
What I would like to do, but cannot get my head around, is to implement some sort of general adapter/wrapper so that I can keep my existing Events and EventHandlers, and use those when dispatching notifications from MediatR, basically reducing the amount of changes for my existing code to revolve around setting up the container.
In terms of code I want to have the following class behave as if it was using the MediatR interfaces.
public class MyHandler : IEventHandler<SampleEvent>
{
public Task Handle(SampleEvent input) => Task.CompletedTask;
}
Any suggestions?