Configuration & Integrations — Events
using System.Text.Json;using EricksonLopez.Events.Bus.Configuration;using EricksonLopez.Events.Bus.Extensions;using EricksonLopez.Events.Serialization.SystemTextJson;using Microsoft.Extensions.DependencyInjection;
namespace Example.EventsConfig;
public static class EventsConfiguration{ public static void Configure(IServiceCollection services, JsonSerializerOptions jsonOptions) { services.AddEventBus(options => { options.ExecutionMode = EventExecutionMode.Sequential; options.ErrorPolicy = ErrorHandlingPolicy.FailFast; options.ScopePolicy = HandlerScopePolicy.Auto; options.MaxReentrancyDepth = 10; });
// Emitted at compile time by EricksonLopez.Events.Generators (v2.0.0+) services.AddGeneratedEventHandlers(); jsonOptions.AddEventsConverters(); }}- CloudEvents (
EricksonLopez.Events.CloudEvents): Convert between envelopes and CNCF CloudEvents via.ToCloudEvent()and.ToEventEnvelope(), and configure STJ withjsonOptions.ConfigureForCloudEvents(). - OpenTelemetry (
EricksonLopez.Events.OpenTelemetry): RegistertracerBuilder.AddEventsInstrumentation()andmeterBuilder.AddEventsInstrumentation().