private static void ConfigureDomainEvents(IServiceCollection services) { var eventRegistry = new DomainEventRegistry(); services.AddSingleton(eventRegistry); services.AddTransient <IEventHandler <ContextAccountCreatedDomainEvent>, ContextAccountCreatedDomainEventHandler>(); services.AddTransient <IEventHandler <CapabilityRegisteredDomainEvent>, CapabilityRegisteredEventHandler>(); services.AddTransient <KafkaConsumerFactory.KafkaConfiguration>(); services.AddTransient <KafkaConsumerFactory>(); var serviceProvider = services.BuildServiceProvider(); var topic = "build.capabilities"; eventRegistry.Register <ContextAccountCreatedDomainEvent>( eventTypeName: "aws_context_account_created", topicName: topic, eventHandler: serviceProvider.GetRequiredService <IEventHandler <ContextAccountCreatedDomainEvent> >()); eventRegistry.Register( eventTypeName: "capability_registered", topicName: topic, eventHandler: serviceProvider.GetRequiredService <IEventHandler <CapabilityRegisteredDomainEvent> >()); services.AddTransient <IEventDispatcher, EventDispatcher>(); }
public async Task Will_Handle_CapabilityRegisteredEvent() { using (var builder = new HttpClientBuilder()) { var teamCreatedEventHandlerStub = new TeamCreatedEventHandlerStub(); var eventRegistry = new DomainEventRegistry(); eventRegistry.Register( eventTypeName: "capability_registered", topicName: "foo", eventHandler: teamCreatedEventHandlerStub); var client = builder .WithService <DomainEventRegistry>(eventRegistry) .Build(); var input = @"{ ""eventName"": ""capability_registered"", ""version"": ""1"", ""payload"": { ""capabilityName"": ""ADFS-ViewOnly"", ""roleArn"": ""arn:aws:iam::738063116313:role/ADFS-ViewOnly"" } }"; var response = await client.PostAsync("/api/events", new JsonContent(input)); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.True(teamCreatedEventHandlerStub.HandleAsyncGotCalled); } }
private void ConfigureDomainEvents(IServiceCollection services) { var eventRegistry = new DomainEventRegistry(); services.AddSingleton <IDomainEventRegistry>(eventRegistry); services.AddSingleton(eventRegistry); services.AddTransient <EventHandlerFactory>(); services.AddTransient <IEventHandler <AWSContextAccountCreatedIntegrationEvent>, AWSContextAccountCreatedEventHandler>(); services.AddTransient <IEventDispatcher, EventDispatcher>(); var capabilitiesTopicName = Configuration["CAPABILITY_SERVICE_KAFKA_TOPIC_CAPABILITY"]; var capabilitiesTopicsTopicName = Configuration["CAPABILITY_SERVICE_KAFKA_TOPIC_TOPICS"]; eventRegistry .Register <CapabilityCreated>("capability_created", capabilitiesTopicName) .Register <CapabilityUpdated>("capability_updated", capabilitiesTopicName) .Register <CapabilityDeleted>("capability_deleted", capabilitiesTopicName) .Register <MemberJoinedCapability>("member_joined_capability", capabilitiesTopicName) .Register <MemberLeftCapability>("member_left_capability", capabilitiesTopicName) .Register <ContextAddedToCapability>("context_added_to_capability", capabilitiesTopicName) .Register <ContextUpdated>("context_updated", capabilitiesTopicName) .Register <AWSContextAccountCreatedIntegrationEvent>("aws_context_account_created", capabilitiesTopicName) .Register <TopicCreated>("topic_created", capabilitiesTopicsTopicName) .Register <ClusterCreated>("cluster_created", capabilitiesTopicsTopicName); var scanner = new DomainEventScanner(eventRegistry); scanner.EnsureNoUnregisteredDomainEventsIn(Assembly.GetExecutingAssembly()); }
private static void ConfigureDomainEvents(IServiceCollection services) { var eventRegistry = new DomainEventRegistry(); services.AddSingleton <IDomainEventRegistry>(eventRegistry); services.AddTransient <KafkaPublisherFactory.KafkaConfiguration>(); services.AddTransient <KafkaPublisherFactory>(); services.AddHostedService <PublishingService>(); var capabilitiesTopicName = "build.capabilities"; eventRegistry .Register <CapabilityCreated>("capability_created", capabilitiesTopicName) .Register <MemberJoinedCapability>("member_joined_capability", capabilitiesTopicName) .Register <MemberLeftCapability>("member_left_capability", capabilitiesTopicName) .Register <ContextAddedToCapability>("context_added_to_capability", capabilitiesTopicName); var scanner = new DomainEventScanner(eventRegistry); scanner.EnsureNoUnregisteredDomainEventsIn(Assembly.GetExecutingAssembly()); }
private static void ConfigureDomainEvents(IServiceCollection services) { var eventRegistry = new DomainEventRegistry(); services.AddSingleton(eventRegistry); services.AddTransient <IEventHandler <ContextAddedToCapabilityDomainEvent>, ContextAddedToCapabilityEventHandler>(); services.AddTransient <KafkaConsumerFactory.KafkaConfiguration>(); services.AddTransient <KafkaConsumerFactory>(); var serviceProvider = services.BuildServiceProvider(); eventRegistry .Register <ContextAddedToCapabilityDomainEvent>( eventTypeName: "context_added_to_capability", topicName: "build.capabilities", eventHandler: serviceProvider.GetRequiredService <IEventHandler <ContextAddedToCapabilityDomainEvent> >()); services.AddTransient <IEventDispatcher, EventDispatcher>(); }
private IServiceProvider GetPreconfiguredServiceProvider() { var loggerFactory = new LoggerFactory(); var logger = new Logger <EventDispatcher>(loggerFactory); var domainEventRegistry = new DomainEventRegistry(); const string topic = "build.capabilities"; domainEventRegistry.Register <MemberJoinedCapabilityDomainEvent>( eventName: "member_joined_capability", topicName: topic); var eventHandlerFactory = new EventHandlerFactory(); var serviceProvider = new ServiceCollection() .AddLogging() .AddTransient <IEventHandler <MemberJoinedCapabilityDomainEvent>, GenericEventHandler <MemberJoinedCapabilityDomainEvent> >() .AddTransient <EventHandlerFactory>() .AddSingleton(domainEventRegistry) .AddTransient <IEventDispatcher, EventDispatcher>() .AddTransient <ExternalEventMetaDataStore>() .BuildServiceProvider(); return(serviceProvider); }