Getting Started with EricksonLopez.Events
dotnet add package EricksonLopez.Events --version 2.0.0<PackageReference Include="EricksonLopez.Events" Version="2.0.0" /><PackageVersion Include="EricksonLopez.Events" Version="2.0.0" />For pure Domain projects that define events without referencing the bus implementation, install EricksonLopez.Events.Contracts (2.0.0).
using System;using System.Threading;using System.Threading.Tasks;using EricksonLopez.Events.Attributes;using EricksonLopez.Events.Bus.Extensions;using EricksonLopez.Events.Contracts;using EricksonLopez.Events.Identifiers;using Microsoft.Extensions.DependencyInjection;
namespace Example.EventsQuickStart;
[EventName("orders.placed")][EventVersion(1)][EventSource("orders-service")]public sealed record OrderPlacedEvent(Guid OrderId, decimal Total) : IDomainEvent{ public EventId Id { get; } = EventId.New(); public DateTimeOffset OccurredAt { get; } = DateTimeOffset.UtcNow;}
public sealed class OrderPlacedHandler : IEventHandler<OrderPlacedEvent>{ public ValueTask HandleAsync(OrderPlacedEvent @event, CancellationToken cancellationToken = default) { return ValueTask.CompletedTask; }}
public static class EventsBootstrap{ public static void Register(IServiceCollection services) { services.AddEventBus(); services.AddEventHandler<OrderPlacedEvent, OrderPlacedHandler>(); }}