public ICloudBusFactory Build(IConfiguration busConfig) { AssemblyScanner scanner = new AssemblyScanner(); // Find all command types List <Type> allCommandTypes = busConfig.CommandType.IsAbstract ? scanner.FindAllTypesExtending(busConfig.CommandType, busConfig.AssembliesToScan).ToList() : scanner.FindAllTypesImplementing(busConfig.CommandType, busConfig.AssembliesToScan).ToList(); // Find all event types List <Type> allEventTypes = busConfig.EventType.IsAbstract ? scanner.FindAllTypesExtending(busConfig.EventType, busConfig.AssembliesToScan).ToList() : scanner.FindAllTypesImplementing(busConfig.EventType, busConfig.AssembliesToScan).ToList(); AzureEnvironmentBuilder builder = new AzureEnvironmentBuilder(clientFactory); // Build a queue for each command type Dictionary <Type, string> commandTypeAndQueueNames = new Dictionary <Type, string>(); foreach (var commandType in allCommandTypes) { string queueName = queueAndTopicNamingConvention.GetQueueNameForCommand(commandType); builder.CreateQueueIfDoesntExist(queueName); commandTypeAndQueueNames.Add(commandType, queueName); } // Build a topic for each event type Dictionary <Type, string> eventTypeAndTopicNames = new Dictionary <Type, string>(); foreach (var eventType in allEventTypes) { string topicName = queueAndTopicNamingConvention.GetTopicNameForEvent(eventType); builder.CreateTopicIfDoesntExist(topicName); eventTypeAndTopicNames.Add(eventType, topicName); } var azureConfig = new AzureBusConfig(commandTypeAndQueueNames, eventTypeAndTopicNames, queueAndTopicNamingConvention, clientFactory); if (azureWorkerConfiguration == null) { return(new AzureCloudBusFactory(busConfig, azureConfig)); } string subscriptionName = azureWorkerConfiguration.SubscriptionNamingConvention.GetSubscriptionName(); foreach (var eventTypeAndTopicName in eventTypeAndTopicNames) { builder.CreateSubscriptionIfDoesntExist(subscriptionName, eventTypeAndTopicName.Value); } return(new AzureCloudBusFactory(busConfig, azureConfig, azureWorkerConfiguration, subscriptionName)); }
public ICloudBusFactory Build(IConfiguration busConfig) { AssemblyScanner scanner = new AssemblyScanner(); // Find all command types List <Type> allCommandTypes = busConfig.CommandType.IsAbstract ? scanner.FindAllTypesExtending(busConfig.CommandType, busConfig.AssembliesToScan).ToList() : scanner.FindAllTypesImplementing(busConfig.CommandType, busConfig.AssembliesToScan).ToList(); // Find all event types List <Type> allEventTypes = busConfig.EventType.IsAbstract ? scanner.FindAllTypesExtending(busConfig.EventType, busConfig.AssembliesToScan).ToList() : scanner.FindAllTypesImplementing(busConfig.EventType, busConfig.AssembliesToScan).ToList(); AwsEnvironmentBuilder builder = new AwsEnvironmentBuilder(ClientFactory); // Build a queue for each command type Dictionary <Type, string> commandTypeAndQueueUri = allCommandTypes.ToDictionary(commandType => commandType, commandType => builder.CreateQueueIfDoesntExist(QueueAndTopicNamingConvention.GetQueueNameForCommand(commandType))); // Build a topic for each event type Dictionary <Type, string> eventTypeAndTopicArns = allEventTypes.ToDictionary(eventType => eventType, eventType => builder.CreateTopicIfDoesntExist(QueueAndTopicNamingConvention.GetTopicNameForEvent(eventType))); var awsConfig = new AwsBusConfig(commandTypeAndQueueUri, eventTypeAndTopicArns, QueueAndTopicNamingConvention, ClientFactory); if (WorkerConfig == null) { return(new AwsCloudBusFactory(busConfig, awsConfig)); } // As we have a worker config, create subscriptions for our events string queueName = WorkerConfig.SubscriptionQueueNamingConvention.GetWorkerQueueName(); string eventSubscriptionQueueUrl = builder.CreateQueueIfDoesntExist(queueName); foreach (var eventTypeAndTopicArn in eventTypeAndTopicArns) { builder.SubscribeQueueToTopic(eventSubscriptionQueueUrl, eventTypeAndTopicArn.Value); } return(new AwsCloudBusFactory(busConfig, awsConfig, WorkerConfig, eventSubscriptionQueueUrl)); }