public static IEventFlowOptions ConfigureAggregates( this IEventFlowOptions eventFlowOptions) { bool commands(Type f) => f.GetInterfaces().Contains(typeof(ICommand)); return(eventFlowOptions .AddEvents(Assembly) .AddCommands(Assembly, commands) .AddCommandHandlers(Assembly)); }
public static IEventFlowOptions ConfigureSagas(this IEventFlowOptions options) { IEventFlowOptions eventFlowOptions = options.AddEvents(typeof(ExampleSagaStartedEvent)) .AddEvents(typeof(ExampleSagaCompletedEvent)) .AddSagas(typeof(ExampleSaga)) .RegisterServices(sr => { sr.RegisterType(typeof(OrderSagaLocator)); }); return(eventFlowOptions); }
public static IEventFlowOptions AddEvents( this IEventFlowOptions eventFlowOptions, Assembly fromAssembly, Predicate <Type> predicate = null) { predicate = predicate ?? (t => true); var aggregateEventTypes = fromAssembly .GetTypes() .Where(t => !t.GetTypeInfo().IsAbstract&& typeof(IAggregateEvent).GetTypeInfo().IsAssignableFrom(t)) .Where(t => predicate(t)); return(eventFlowOptions.AddEvents(aggregateEventTypes)); }
public async Task BasicFlow(IEventFlowOptions eventFlowOptions) { // Arrange using (var resolver = eventFlowOptions .AddEvents(EventFlowTestHelpers.Assembly) .AddCommandHandlers(EventFlowTestHelpers.Assembly) .RegisterServices(f => f.Register <IPingReadModelLocator, PingReadModelLocator>()) .AddMetadataProvider <AddGuidMetadataProvider>() .AddMetadataProvider <AddMachineNameMetadataProvider>() .AddMetadataProvider <AddEventTypeMetadataProvider>() .UseInMemoryReadStoreFor <InMemoryThingyReadModel>() .UseInMemoryReadStoreFor <PingReadModel, IPingReadModelLocator>() .RegisterServices(sr => sr.Register <IScopedContext, ScopedContext>(Lifetime.Scoped)) .AddSubscribers(typeof(Subscriber)) .CreateResolver()) { var commandBus = resolver.Resolve <ICommandBus>(); var eventStore = resolver.Resolve <IAggregateStore>(); var queryProcessor = resolver.Resolve <IQueryProcessor>(); var id = ThingyId.New; // Act await commandBus.PublishAsync(new ThingyDomainErrorAfterFirstCommand(id), CancellationToken.None).ConfigureAwait(false); await commandBus.PublishAsync(new ThingyPingCommand(id, PingId.New), CancellationToken.None).ConfigureAwait(false); await commandBus.PublishAsync(new ThingyPingCommand(id, PingId.New), CancellationToken.None).ConfigureAwait(false); var testAggregate = await eventStore.LoadAsync <ThingyAggregate, ThingyId>(id, CancellationToken.None).ConfigureAwait(false); var testReadModelFromQuery1 = await queryProcessor.ProcessAsync( new ReadModelByIdQuery <InMemoryThingyReadModel>(id.Value), CancellationToken.None) .ConfigureAwait(false); var testReadModelFromQuery2 = await queryProcessor.ProcessAsync( new InMemoryQuery <InMemoryThingyReadModel>(rm => rm.DomainErrorAfterFirstReceived), CancellationToken.None) .ConfigureAwait(false); var pingReadModels = await queryProcessor.ProcessAsync( new InMemoryQuery <PingReadModel>(m => true), CancellationToken.None) .ConfigureAwait(false); // Assert pingReadModels.Should().HaveCount(2); testAggregate.DomainErrorAfterFirstReceived.Should().BeTrue(); testReadModelFromQuery1.DomainErrorAfterFirstReceived.Should().BeTrue(); testReadModelFromQuery2.Should().NotBeNull(); } }
public static IEventFlowOptions AddDefaults( this IEventFlowOptions eventFlowOptions, Assembly fromAssembly, Predicate <Type> predicate = null) { return(eventFlowOptions .AddEvents(fromAssembly, predicate) .AddJobs(fromAssembly, predicate) .AddCommands(fromAssembly, predicate) .AddCommandHandlers(fromAssembly, predicate) .AddMetadataProviders(fromAssembly, predicate) .AddSubscribers(fromAssembly, predicate) .AddEventUpgraders(fromAssembly, predicate) .AddQueryHandlers(fromAssembly, predicate)); }
public static IEventFlowOptions AddEvents( this IEventFlowOptions eventFlowOptions, params Type[] aggregateEventTypes) { return(eventFlowOptions.AddEvents((IEnumerable <Type>)aggregateEventTypes)); }
private void RegisterEvents(IEventFlowOptions eventFlowOptions) { eventFlowOptions.AddEvents(typeof(TestCreated)); }