This package is meant to be used with OrchardCore. List events, handle them and get a history in a relational table besides your other tables.
This will work only with SQL-Server, Postgres and MySQL. I didn't find a way to get this working with SQLite.
- Install the package via nuget in the project that consumes the API
- Add code that interacts with the event service. This is the main interface for storing, reading and processing the events.
// Example from the repository with a content part handler public class BookHandler : ContentPartHandler<Book> { private readonly IServiceProvider _serviceProvider; public BookHandler(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } public override async Task PublishedAsync(PublishContentContext context, Book instance) { var eventService = _serviceProvider.GetRequiredService<IEventService>(); await eventService.Add(instance.BookTitle.Text, "BookAddedEvent", instance.ContentItem.ContentItemId); await base.PublishedAsync(context, instance); } }
- Activate the feature in the tenant you want to use it for
- You can view the created events in the 'Events' menu point in the admin frontend
Directly taken from the interface:
Task<Guid> Add(object payload, string friendlyName, string? referenceId = null, Guid? originalEventId = null);
The payload can be any object as long as it is serializable. You can use referenceId to query via the event repository (e.g. for linking content items or storing other information).
// Gets the oldest event pending from the event store
Task<Event> GetNextPending(string? referenceId = null);
Again, you can use the referenceId for querying a specific event.
// Set the event state of a specific event
Task SetInProcessing(Guid eventId);
Task SetAsProcessed(Guid eventId);
Task SetAsFailed(Guid eventId);
Task SetAsAborted(Guid eventId);