public async Task <bool> Dispatch(EventEnvelope eventEnvelope) { try { using (var scope = scopeFactory.CreateScope()) { scope.ServiceProvider.GetRequiredService <CallContext>().InitializeCallContextFrom(eventEnvelope.CallContext); var eventBus = scope.ServiceProvider.GetRequiredService <EventBus>(); await eventBus.PublishEventAsync(eventEnvelope.Event); } } catch (Exception ex) { logger.LogError(ex, "Error during event processing"); return(false); } return(true); }
private string SerializeEventEnvelope(EventEnvelope eventEnvelope) { var jsonSerializerSettings = jsonSerializerSettingsProvider.GetJsonSerializerSettings(); return(JsonConvert.SerializeObject(eventEnvelope, jsonSerializerSettings)); }