public static void AddPostgresAperture( this IServiceCollection services, PullEventStream.Config config = default, Func <ApertureAgent, ApertureAgent> configure = null) { services.AddScoped <PostgresOffsetTracker>(); services.AddScoped <IStreamEvents>( ctx => new PullEventStream( ctx.GetService <IPullEventStreamEventStore>(), config)); var agent = ApertureAgentBuilder .CreateDefault(); services.AddSingleton( ctx => { foreach (var projection in ctx.GetServices <IProjectEvents>()) { agent.AddProjection(projection); } if (configure != null) { agent = configure(agent); } return(agent .UseEventStream(ctx.GetService <IStreamEvents>())); }); }
public async Task Default_Configuration_Projects_Events() { var sciFiEvents = new List <IEvent> { new MovieAddedToCatalogue("A third movie", Genre.SciFi), new MovieAddedToCatalogue("Fourth movie", Genre.SciFi), }; var crimeEvents = new List <IEvent> { new MovieAddedToCatalogue("A movie", Genre.Crime), new MovieAddedToCatalogue("A second movie", Genre.Crime), new MovieAddedToCatalogue("Another movie", Genre.Crime) }; var eventStream = new PullEventStream( new EventStore( sciFiEvents.Concat(crimeEvents).ToList() ), new PullEventStream.Config { PullInterval = TimeSpan.FromMilliseconds(10) } ); var offsetTracker = new Mock <ITrackOffset>(); offsetTracker .Setup(t => t.GetOffsetAsync(It.IsAny <Type>())) .ReturnsAsync(0); var sciFiProjection = new SciFiMoviesProjection(offsetTracker.Object); var crimeProjection = new CrimeMoviesProjection(offsetTracker.Object); var cts = new CancellationTokenSource(2000); await Assert.ThrowsAsync <TaskCanceledException>( async() => await ApertureAgentBuilder .CreateDefault() .UseCancellationTokenSource(cts) .AddProjection(sciFiProjection) .AddProjection(crimeProjection) .UseEventStream(eventStream) .StartAsync()); sciFiProjection.Events .Should() .BeEquivalentTo(sciFiEvents); crimeProjection.Events .Should() .BeEquivalentTo(crimeEvents); }
public static void AddApertureAgent(this IServiceCollection services) { services.AddDefaultPullEventStream(); services.AddOffsetTracker(); services.AddProjections(); services.AddSingleton( ctx => ApertureAgentBuilder .CreateDefault() .AddProjection(ctx.GetService <SciFiMoviesServerProjection>()) .AddProjection(ctx.GetService <CrimeMovieServerProjection>()) .UseRestartWithBackOffSupervision() .UseEventStream(ctx.GetService <IStreamEvents>())); }