public void SetDependencyLifetimeScopeFactory_PassingNullAsDependencyLifetimeScopeFactory_ShouldThrowException() { var builder = new ProjectorBuilder <string, FakeMessageEnvelope>(); var ex = Assert.Throws <ArgumentNullException>(() => builder.SetDependencyLifetimeScopeFactory(null)); Assert.That(ex.ParamName, Is.EqualTo("factory")); }
public void Register_PassingNullAsMultipleProjections_ShouldThrowException() { var builder = new ProjectorBuilder <string, FakeMessageEnvelope>(); var ex = Assert.Throws <ArgumentNullException>(() => builder.Register((Projection <string, FakeConnection, FakeMessageEnvelope>[])null)); Assert.That(ex.ParamName, Is.EqualTo("projections")); }
RegisterProjectionsFromAutofac <TProjectionKey, TMessageEnvelope>(this ProjectorBuilder <TProjectionKey, TMessageEnvelope> builder, IComponentContext componentContext) where TProjectionKey : IEquatable <TProjectionKey> where TMessageEnvelope : MessageEnvelope { var projections = componentContext.Resolve <IEnumerable <IProjection <TProjectionKey, TMessageEnvelope> > >(); builder.Register(projections); return(builder); }
UseAutofacDependencyLifetimeScopeFactory <TProjectionKey, TMessageEnvelope>(this ProjectorBuilder <TProjectionKey, TMessageEnvelope> builder, IComponentContext componentContext) where TProjectionKey : IEquatable <TProjectionKey> where TMessageEnvelope : MessageEnvelope { var lifetimeScopeFactory = componentContext.Resolve <Func <ILifetimeScope> >(); Func <ILifetimeScope> childLifetimeScopeFactory = () => lifetimeScopeFactory().BeginLifetimeScope(); builder.SetDependencyLifetimeScopeFactory(new AutofacDependencyLifetimeScopeFactory(childLifetimeScopeFactory)); return(builder); }
public void Build_WithCertainDependencyLifetimeScopeFactory_ShouldGetPassedToProjectorInstance() { var projection = new TestProjection("A"); var builder = new ProjectorBuilder <string, FakeMessageEnvelope>(); builder.Register(projection).SetDependencyLifetimeScopeFactory(_factoryMock.Object); var projector = builder.Build <TestNextSequenceNumberRepository>(); Assert.That(projector.DependencyLifetimeScopeFactory, Is.EqualTo(_factoryMock.Object)); }
public void Build_WithMultipleProjectionsRegistered_ShouldGetPassedToProjectorInstance() { var projections = new[] { new TestProjection("A"), new TestProjection("B") }; var builder = new ProjectorBuilder <string, FakeMessageEnvelope>(); builder.Register(projections).SetDependencyLifetimeScopeFactory(_factoryMock.Object); var projector = builder.Build <TestNextSequenceNumberRepository>(); Assert.That(projector.Projections.Length, Is.EqualTo(2)); Assert.That(projector.Projections[0], Is.EqualTo(projections[0])); Assert.That(projector.Projections[1], Is.EqualTo(projections[1])); }
public static async Task Main(string[] args) { /* * API NOTES * * For tagged events we will probably use IProjectionLocator to map tagged events to their appropriate keys. * * ProjectionManager will be an actor that has been propsed up for sending Source<EventEnvelope, NotUsed> to child projector * child projector will have an Id and this Id will either be a consequence of it being a persistentId or it will * be a consequence of it being a Tag + ProjectionLocator */ var config = ConfigurationFactory.ParseString(Config.Postgres); var eventMapBuilder = new EventMapBuilder <GiftCardProjection, GiftCardProjectionId, GiftCardProjectionContext>(); eventMapBuilder.Map <DomainEvent <GiftCard, GiftCardId, IssuedEvent> >() .AsCreateOf(x => IProjectionIdExtensions.From(x.AggregateIdentity)) .Using((projection, evt) => { projection.Credits = evt.AggregateEvent.Credits; projection.IsCancelled = false; projection.Issued = evt.Timestamp.UtcDateTime; }); eventMapBuilder.Map <DomainEvent <GiftCard, GiftCardId, RedeemedEvent> >() .AsUpdateOf(x => { return(IProjectionIdExtensions.From(x.AggregateIdentity)); }) .Using((projection, evt) => { projection.Credits -= evt.AggregateEvent.Credits; }); eventMapBuilder.Map <DomainEvent <GiftCard, GiftCardId, CancelledEvent> >() .AsUpdateOf(x => IProjectionIdExtensions.From(x.AggregateIdentity)) .Using((projection, evt) => { projection.IsCancelled = false; }); var builder = ProjectorBuilder .Create("giftcard-projection-manager", config); var repositoryActor = builder.ActorSystem.ActorOf(Props.Create(() => new RepositoryActor <GiftCardProjection, GiftCardProjectionId>()), "repository-actor-monkas"); var projectorMap = new ProjectorMap <GiftCardProjection, GiftCardProjectionId, GiftCardProjectionContext> { Create = async(key, context, projector, shouldOverride) => { var projection = new GiftCardProjection() { Id = key }; await projector(projection); repositoryActor.Tell(new Create <GiftCardProjection, GiftCardProjectionId> { Projection = projection }); }, Update = async(key, context, projector, createIfMissing) => { var query = new Read <GiftCardProjectionId> { Key = key }; var projection = await repositoryActor.Ask <GiftCardProjection>(query); await projector(projection); repositoryActor.Tell(new Update <GiftCardProjection, GiftCardProjectionId> { Projection = projection }); }, Delete = (key, context) => { var command = new Delete <GiftCardProjectionId> { Key = key }; repositoryActor.Tell(command); return(Task.FromResult(true)); }, Custom = (context, projector) => projector() }; builder .Using <SqlReadJournal>(SqlReadJournal.Identifier) .WithEventMapBuilder(eventMapBuilder) .WithProjectorBuilder(projectorMap) .RunAggregateProjection(repositoryActor); /* * * ProjectorBuilder * .Create("GiftCardProjectionManager", config) * .Using<SqlReadJournal>(SqlReadJournal.Identifier) * .WithEventMap(GiftCardProjector.GetEventMap()) * .RunAggregateProjection(); * * ProjectorBuilder * .Create("IssuedGiftCardsProjecection", config) * .Using<SqlReadJournal>(SqlReadJournal.Identifier) * .WithEventMap(GiftCardProjector.GetEventMapForIssued()) * .Using<ProjectorLocator>(locator) * .RunTaggedEventProjection(); * * */ Console.WriteLine(" here "); Console.ReadLine(); }