public static void AddCommandHandlers(this IServiceCollection services, params Assembly[] assemblies)
        {
            var manager  = StaticHelpers.GetHandlerManager(services);
            var handlers = assemblies.FindHandlers(typeof(ICommandHandler <>), typeof(ICommandHandler <,>));

            foreach (var handler in handlers)
            {
                manager.CommandHandlers.Add(handler);
                services.AddScoped(handler.ServiceType, handler.ImplementationType);
            }
        }
        public static void AddDistributedEventListeners(this IServiceCollection services, params Assembly[] assemblies)
        {
            var manager   = StaticHelpers.GetHandlerManager(services);
            var listeners = assemblies.FindHandlers(typeof(IDistributedEventListener <>));

            foreach (var listener in listeners)
            {
                manager.DistributedEventListeners.Add(listener);
                services.AddSingleton(listener.ImplementationType);
            }
        }
        public static void AddFaultHandlers(this IServiceCollection services, params Assembly[] assemblies)
        {
            var manager   = StaticHelpers.GetHandlerManager(services);
            var listeners = assemblies.FindHandlers(typeof(IFaultHandler <>));

            foreach (var listener in listeners)
            {
                manager.FaultHandlers.Add(listener);
                services.AddScoped(listener.ImplementationType);
            }
        }
        public static void AddMassTransitMessageBus(this IServiceCollection services, MassTransitMessageBusOptions options)
        {
            if (options == null)
            {
                throw new ArgumentException(nameof(options));
            }

            // Force the adding of the HandlerManager
            StaticHelpers.GetHandlerManager(services);

            services.AddSingleton(s => new MassTransitMessageBus(options, s.GetRequiredService <HandlerManager>(), s, s.GetRequiredService <ILoggerFactory>()));
            services.AddSingleton <ICommandSender>(s => s.GetService <MassTransitMessageBus>());
            services.AddSingleton <ICommandSenderReceiver>(s => s.GetService <MassTransitMessageBus>());
            services.AddSingleton <IEventPublisher>(s => s.GetService <MassTransitMessageBus>());
        }