private void CreateQueuesAsync(IEnumerable <Type> commandTypes, EventHubService service)
 {
     foreach (var commandType in commandTypes)
     {
         service.RegisterCommand(commandType);
     }
 }
 private void CreateEventsAsync(IEnumerable <Type> eventTypes, EventHubService service)
 {
     foreach (var eventType in eventTypes)
     {
         service.RegisterEvent(eventType);
     }
 }
 private void CreateHandledQueuesAsync(IEnumerable <Type> handlerTypes, EventHubService service)
 {
     foreach (var handlerType in handlerTypes)
     {
         service.RegisterCommandHandler(handlerType);
     }
 }
 private void CreateSpecificEventsAsync(EventHubService service)
 {
     if (_eventTypes == null)
     {
         return;
     }
     CreateEventsAsync(_eventTypes, service);
 }
 private void CreateSpecificHandledEventsAsync(EventHubService service)
 {
     if (_eventHandlerTypes == null)
     {
         return;
     }
     CreateHandledEventsAsync(_eventHandlerTypes, service);
 }
 private void CreateSpecificQueuesAsync(EventHubService service)
 {
     if (_messageTypes == null)
     {
         return;
     }
     CreateQueuesAsync(_messageTypes, service);
 }
        public async Task <EventHubService> BuildAsync()
        {
            var hubService = new EventHubService(_handlerActivator, _exceptionLogger, _settings, _hubEventErrorBus, _hubCommandErrorBus, _logger);

            CreateHandledQueuesInAssembliesAsync(hubService);
            CreateSpecificHandledQueuesAsync(hubService);
            CreateQueuesInAssembliesAsync(hubService);
            CreateSpecificQueuesAsync(hubService);
            CreateHandledEventsInAssembliesAsync(hubService);
            CreateSpecificHandledEventsAsync(hubService);
            CreateEventsInAssembliesAsync(hubService);
            CreateSpecificEventsAsync(hubService);

            await hubService.Start().ConfigureAwait(false);

            return(hubService);
        }
        private void CreateEventsInAssembliesAsync(EventHubService service)
        {
            if (_eventAssembliesToScan == null)
            {
                return;
            }
            var assemblies = GetAssemblies(_eventAssembliesToScan);

            var eventTypesInAssemblies = assemblies
                                         .SelectMany(assembly => assembly.GetTypes())
                                         .Where(type => type.DoesTypeImplementInterface(typeof(IHubEvent)))
                                         .ToList();

            var found = string.Join(",", eventTypesInAssemblies.Select(e => e.Name));

            _logger.Debug(Context, $"Found the following hub events: {found}");

            CreateEventsAsync(eventTypesInAssemblies, service);
        }
        private void CreateHandledQueuesInAssembliesAsync(EventHubService service)
        {
            if (_messageHandlerAssembliesToScan == null)
            {
                return;
            }

            var assemblies = GetAssemblies(_messageHandlerAssembliesToScan);

            var handlerTypesInAssemblies = assemblies
                                           .SelectMany(assembly => assembly.GetTypes())
                                           .Where(type => type.DoesTypeImplementInterface(typeof(IHubCommandHandler <>)))
                                           .ToList();

            var found = string.Join(",", handlerTypesInAssemblies.Select(e => e.Name));

            _logger.Debug(Context, $"Found the following hub command handlers: {found}");

            CreateHandledQueues(handlerTypesInAssemblies, service);
        }