partial void OnCreateContainer(UnityContainer container) { var metadata = container.Resolve <IMetadataProvider>(); var serializer = container.Resolve <ITextSerializer>(); // blob var blobStorageAccount = CloudStorageAccount.Parse(azureSettings.BlobStorage.ConnectionString); container.RegisterInstance <IBlobStorage>(new CloudBlobStorage(blobStorageAccount, azureSettings.BlobStorage.RootContainerName)); var commandBus = new CommandBus(new TopicSender(azureSettings.ServiceBus, Topics.Commands.Path), metadata, serializer); var eventsTopicSender = new TopicSender(azureSettings.ServiceBus, Topics.Events.Path); container.RegisterInstance <IMessageSender>("events", eventsTopicSender); container.RegisterInstance <IMessageSender>("orders", new TopicSender(azureSettings.ServiceBus, Topics.EventsOrders.Path)); container.RegisterInstance <IMessageSender>("seatsavailability", new TopicSender(azureSettings.ServiceBus, Topics.EventsAvailability.Path)); var eventBus = new EventBus(eventsTopicSender, metadata, serializer); var sessionlessCommandProcessor = new CommandProcessor(new SubscriptionReceiver(azureSettings.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.Sessionless, false, new SubscriptionReceiverInstrumentation(Topics.Commands.Subscriptions.Sessionless, this.instrumentationEnabled)), serializer); var seatsAvailabilityCommandProcessor = new CommandProcessor(new SessionSubscriptionReceiver(azureSettings.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.Seatsavailability, false, new SessionSubscriptionReceiverInstrumentation(Topics.Commands.Subscriptions.Seatsavailability, this.instrumentationEnabled)), serializer); var synchronousCommandBus = new SynchronousCommandBusDecorator(commandBus); container.RegisterInstance <ICommandBus>(synchronousCommandBus); container.RegisterInstance <IEventBus>(eventBus); container.RegisterInstance <IProcessor>("SessionlessCommandProcessor", sessionlessCommandProcessor); container.RegisterInstance <IProcessor>("SeatsAvailabilityCommandProcessor", seatsAvailabilityCommandProcessor); RegisterRepositories(container); RegisterEventProcessors(container); RegisterCommandHandlers(container, sessionlessCommandProcessor, seatsAvailabilityCommandProcessor); // handle order commands inline, as they do not have competition. synchronousCommandBus.Register(container.Resolve <ICommandHandler>("OrderCommandHandler")); // message log var messageLogAccount = CloudStorageAccount.Parse(azureSettings.MessageLog.ConnectionString); container.RegisterInstance <IProcessor>("EventLogger", new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.Events.Path, Topics.Events.Subscriptions.Log))); container.RegisterInstance <IProcessor>("OrderEventLogger", new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.EventsOrders.Path, Topics.EventsOrders.Subscriptions.LogOrders))); container.RegisterInstance <IProcessor>("SeatsAvailabilityEventLogger", new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.EventsAvailability.Path, Topics.EventsAvailability.Subscriptions.LogAvail))); container.RegisterInstance <IProcessor>("CommandLogger", new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.Log))); }
partial void OnCreateContainer(IServiceCollection services, ITextSerializer serializer, IMetadataProvider metadata, ILoggerFactory loggerFactory) { var azureSettings = InfrastructureSettings.Read("Application\\Settings.xml"); var busConfig = new ServiceBusConfig(azureSettings.ServiceBus, loggerFactory); busConfig.Initialize(); // blob var blobStorageAccount = CloudStorageAccount.Parse(azureSettings.BlobStorage.ConnectionString); services.AddSingleton <IBlobStorage>(new CloudBlobStorage(blobStorageAccount, azureSettings.BlobStorage.RootContainerName, loggerFactory.CreateLogger <CloudBlobStorage>())); var topicLogger = loggerFactory.CreateLogger <TopicSender>(); var commandBus = new CommandBus(new TopicSender(azureSettings.ServiceBus, Topics.Commands.Path, topicLogger), metadata, serializer); var eventsTopicSender = new TopicSender(azureSettings.ServiceBus, Topics.Events.Path, topicLogger); services.AddSingleton <IMessageSender>(eventsTopicSender); services.AddSingleton <IMessageSender>(/*"orders", */ new TopicSender(azureSettings.ServiceBus, Topics.EventsOrders.Path, topicLogger)); services.AddSingleton <IMessageSender>(/*"seatsavailability",*/ new TopicSender(azureSettings.ServiceBus, Topics.EventsAvailability.Path, topicLogger)); var eventBus = new EventBus(eventsTopicSender, metadata, serializer); var subscriptionLogger = loggerFactory.CreateLogger <SubscriptionReceiver>(); var sessionSubscriptionLogger = loggerFactory.CreateLogger <SessionSubscriptionReceiver>(); var sessionlessCommandProcessor = new CommandProcessor(new SubscriptionReceiver(azureSettings.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.Sessionless, false, subscriptionLogger), serializer, loggerFactory.CreateLogger <CommandProcessor>()); var anchorsAvailabilityCommandProcessor = new CommandProcessor(new SessionSubscriptionReceiver(azureSettings.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.Anchorsavailability, false, sessionSubscriptionLogger), serializer, loggerFactory.CreateLogger <CommandProcessor>()); var synchronousCommandBus = new SynchronousCommandBusDecorator(commandBus, loggerFactory.CreateLogger <SynchronousCommandBusDecorator>()); services.AddSingleton <ICommandBus>(synchronousCommandBus); services.AddSingleton <IEventBus>(eventBus); services.AddSingleton <IProcessor>(/*"SessionlessCommandProcessor", */ sessionlessCommandProcessor); services.AddSingleton <IProcessor>(/*"AnchorsAvailabilityCommandProcessor", */ anchorsAvailabilityCommandProcessor); RegisterRepositories(services, azureSettings, loggerFactory); var serviceProvider = services.BuildServiceProvider(); RegisterEventProcessors(services, serviceProvider, busConfig, serializer, loggerFactory); var commandHandlers = serviceProvider.GetServices <ICommandHandler>().ToList(); RegisterCommandHandlers(services, commandHandlers, sessionlessCommandProcessor, anchorsAvailabilityCommandProcessor); // handle order commands inline, as they do not have competition. // TODO: Get exactly OrderCommandHandler synchronousCommandBus.Register(commandHandlers.First(s => s.GetType() == typeof(OrderCommandHandler))); // message log var messageLogAccount = CloudStorageAccount.Parse(azureSettings.MessageLog.ConnectionString); services.AddSingleton <IProcessor>(/*"EventLogger", */ new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.Events.Path, Topics.Events.Subscriptions.Log, true, subscriptionLogger))); services.AddSingleton <IProcessor>(/*"OrderEventLogger", */ new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.EventsOrders.Path, Topics.EventsOrders.Subscriptions.LogOrders, true, subscriptionLogger))); services.AddSingleton <IProcessor>(/*"SeatsAvailabilityEventLogger", */ new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.EventsAvailability.Path, Topics.EventsAvailability.Subscriptions.LogAvail, true, subscriptionLogger))); services.AddSingleton <IProcessor>(/*"CommandLogger", */ new AzureMessageLogListener( new AzureMessageLogWriter(messageLogAccount, azureSettings.MessageLog.TableName), new SubscriptionReceiver(azureSettings.ServiceBus, Topics.Commands.Path, Topics.Commands.Subscriptions.Log, true, subscriptionLogger))); }