private static async Task <IAppBuilder> UsePlatibusMiddlewareAsync(this IAppBuilder app,
                                                                           IOwinConfiguration configuration)
        {
            var baseUri = configuration.BaseUri;
            var subscriptionTrackingService = configuration.SubscriptionTrackingService;
            var messageQueueingService      = configuration.MessageQueueingService;

            var transportServiceOptions = new HttpTransportServiceOptions(baseUri, messageQueueingService, subscriptionTrackingService)
            {
                DiagnosticService = configuration.DiagnosticService,
                Endpoints         = configuration.Endpoints,
                MessageJournal    = configuration.MessageJournal,
                BypassTransportLocalDestination = configuration.BypassTransportLocalDestination
            };

            var transportService = new HttpTransportService(transportServiceOptions);
            var bus = new Bus(configuration, baseUri, transportService, messageQueueingService);

            await transportService.Init();

            await bus.Init();

            var middleware = new PlatibusMiddleware(configuration, bus, transportService);

            var appProperties = new AppProperties(app.Properties);

            appProperties = appProperties.Set("platibus.Bus", bus);
            appProperties.OnAppDisposing.Register(() =>
            {
                middleware.Dispose();
                transportService.Dispose();
                bus.Dispose();
                (messageQueueingService as IDisposable)?.Dispose();
                (subscriptionTrackingService as IDisposable)?.Dispose();
            });

            return(app.Use(middleware.Invoke));
        }