public static void EnqueuePendingEvents( this IAppBuilder app, IEventPublisher eventPublisher) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (eventPublisher == null) { throw new ArgumentNullException(nameof(eventPublisher)); } var appProperties = new AppProperties(app.Properties); CancellationToken cancellationToken = appProperties.OnAppDisposing; eventPublisher.EnqueueAll(cancellationToken); }