public static ICommandRegistry AddNotificationClient(this ICommandRegistry commandRegistry, string serviceBusConnectionString)
        {
            // Configure the SendEmailCommand to be dispatched to a service bus queue
            QueueClient queueClient = new QueueClient(serviceBusConnectionString, "sendEmailQueue");

            commandRegistry.Register <SendEmailCommand>(queueClient.CreateCommandDispatcherFactory());
            return(commandRegistry);
        }
        private static ICommandDispatcher ConfigureForDispatchToQueue()
        {
            if (_dispatchServiceProvider == null)
            {
                IServiceCollection serviceCollection         = new ServiceCollection();
                CommandingDependencyResolverAdapter resolver = new CommandingDependencyResolverAdapter(
                    (fromType, toInstance) => serviceCollection.AddSingleton(fromType, toInstance),
                    (fromType, toType) => serviceCollection.AddTransient(fromType, toType),
                    (resolveType) => _dispatchServiceProvider.GetService(resolveType));
                ICommandRegistry commandRegistry = resolver.AddCommanding();
                resolver.AddAzureServiceBus();

                // register our command to dispatch to a servie bus queue
                QueueClient client = new QueueClient(ServiceBusConnectionString, "myqueue");
                commandRegistry.Register <SimpleCommand>(client.CreateCommandDispatcherFactory());

                _dispatchServiceProvider = serviceCollection.BuildServiceProvider();
            }


            ICommandDispatcher dispatcher = _dispatchServiceProvider.GetService <ICommandDispatcher>();

            return(dispatcher);
        }