EpiEvents is a library which makes it easier to handle Episerver events by using a mediator. EpiEvents allows a developer to handle an Episerver event by implementing an event handler for the event he cares.
EpiEvents.Core implements Episerver content event handling.
EpiEvents.Commerce implements Episerver Commerce event handling.
Install using NuGet.
Install-Package EpiEvents.Core
Install-Package EpiEvents.Commerce
You have to configure MediatR according to its latest documentation. If you are using MediatR only for EpiEvents, it is enough to configure only notification handlers. Below is an example of the StructureMap configuration for it.
Scan(x =>
{
x.TheCallingAssembly();
x.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
x.ConnectImplementationsToTypesClosing(typeof(IAsyncNotificationHandler<>));
});
For<SingleInstanceFactory>().Use<SingleInstanceFactory>(ctx => t => ctx.GetInstance(t));
For<MultiInstanceFactory>().Use<MultiInstanceFactory>(ctx => t => ctx.GetAllInstances(t));
For<IMediator>().Use<Mediator>();
You also have to configure EpiEvent settings in the StructureMap config.
For<EpiEvents.Core.ISettings>().Use<EpiEvents.Core.DefaultSettings>();
Default settings disables all loading events. Loading events causes Episerver to slow down. But you can enable loading events in the appSettings.
<add key="EpiEvents:EnableLoadingEvents" value="true" />
The package implements all events of IContentEvents interface. You can find a full list of events under src/EpiEvents.Core/Events. There are some differences, though - there are some additional events. For example, there is a CopyingContent event which is not found in the IContentEvents. This event is triggered by the content copying instead of a CreatingContent event with CopyContentEventArgs. More info about content events can be found in the Episerver Content Events Explained article.
Handling of an event is simple. Create MediatR's INotificationHandler with a type parameter of the event you want to handle.
public class SampleHandler : INotificationHandler<CreatedContent>
{
public void Handle(CreatedContent notification)
{
// Handle your event
}
}