Beispiel #1
0
        public void EventSourcingPod_FromJson()
        {
            var tkd = new TypeKeyDirectory();

            tkd.Register <MockEvent>();

            var id   = Guid.Parse("52d307a2-39ba-47e2-b73f-2faf0727d44e");
            var json = @"
			{
				""PayloadKey"": ""MockEvent"",
				""TargetVersion"": 10,
				""Payload"": {
					""AggregateId"": ""52d307a2-39ba-47e2-b73f-2faf0727d44e"",
					""Name"": ""mockName""
				}
			}"            ;

            var pod = json.FromJson <EventSourcingPod>();

            Assert.Equal("MockEvent", pod.PayloadKey);
            Assert.Equal(10, pod.TargetVersion);
            Assert.False(pod.PayloadHasValue);
            Assert.Null(pod.Payload);

            var evt = pod.WithTypeKeyDirectory(tkd);

            Assert.Equal(id, evt.AggregateId);
            Assert.IsType <MockEvent>(evt);
            var mevt = (MockEvent)evt;

            Assert.Equal("mockName", mevt.Name);
            Assert.Equal(10, mevt.EventSourcing().TargetVersion);
        }
Beispiel #2
0
 public RabbitMQEventBus(
     IServiceProvider serviceProvider,
     IRabbitMQPersistentConnection persistentConnection,
     TypeKeyDirectory typeKeyDirectory,
     string exchangeName,
     string queueName,
     int retryCount)
 {
     this.serviceProvider      = serviceProvider;
     this.persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
     this.typeKeyDirectory     = typeKeyDirectory;
     this.exchangeName         = exchangeName;
     this.queueName            = queueName;
     this.retryCount           = retryCount;
     _consumerChannel          = CreateConsumerChannel();
 }
Beispiel #3
0
 public InMemoryEventStorage(TypeKeyDirectory typeKeyDirectory, string dumpFilePath = null)
 {
     if (dumpFilePath != null)
     {
         this.dumpFilePath = new Locker <string>(dumpFilePath);
         this.dumpFilePath.Read(path =>
         {
             if (File.Exists(path))
             {
                 var dic = File.ReadAllText(path).FromJson <Dictionary <Guid, List <EventSourcingPod> > >();
                 events.WriteObject(dic.Select((KeyValuePair <Guid, List <EventSourcingPod> > k) => new
                 {
                     k.Key,
                     Value = k.Value.Select <EventSourcingPod, Event>((EventSourcingPod v) => v.WithTypeKeyDirectory(typeKeyDirectory)).ToList <Event>()
                 }).ToDictionary(a => a.Key, a => a.Value));
             }
         });
     }
 }
Beispiel #4
0
 public InMemorySnapshotStorage(TypeKeyDirectory typeKeyDirectory, string dumpFilePath = null)
 {
     if (dumpFilePath != null)
     {
         this.dumpFilePath = new Locker <string>(dumpFilePath);
         this.dumpFilePath.Read(path =>
         {
             if (File.Exists(path))
             {
                 var dic = File.ReadAllText(path).FromJson <Dictionary <string, List <JsonPod <Snapshot, string> > > >();
                 snapshots.WriteObject(dic.Select((KeyValuePair <string, List <JsonPod <Snapshot, string> > > k) => new
                 {
                     Key   = k.Key,
                     Value = k.Value.Select <JsonPod <Snapshot, string>, Snapshot>((JsonPod <Snapshot, string> v) => (Snapshot)v.As(typeKeyDirectory[k.Key])).ToDictionary <Snapshot, Guid>((Snapshot s) => s.AggregateId)
                 }).ToDictionary(a => a.Key, a => a.Value));
             }
         });
     }
 }
        public static IServiceCollection AddFuxion(this IServiceCollection me, Action <IFuxionBuilder> builderAction)
        {
            var typeKeyDirectory = new TypeKeyDirectory();

            me.AddSingleton(typeKeyDirectory);
            var builder = new FuxionBuilder(me, typeKeyDirectory);

            builderAction(builder);
            foreach (var action in builder.PostRegistrationsList)
            {
                var sp = me.BuildServiceProvider();
                action(sp);
            }
            foreach (var(type, preAction, postAction) in builder.AutoActivateList)
            {
                IServiceProvider sp = me.BuildServiceProvider();
                preAction?.Invoke(sp);
                var obj = sp.GetRequiredService(type);
                postAction?.Invoke(sp, obj);
            }
            return(me);
        }
Beispiel #6
0
 public Event WithTypeKeyDirectory(TypeKeyDirectory typeKeyDirectory) => AsEvent(typeKeyDirectory[PayloadKey]);
 public FuxionBuilder(IServiceCollection services, TypeKeyDirectory typeKeyDirectory)
 {
     Services         = services;
     TypeKeyDirectory = typeKeyDirectory;
 }
Beispiel #8
0
 public EventStoreStorage(IEventStoreConnection connection, TypeKeyDirectory typeKeyDirectory)
 {
     this.connection       = connection;
     this.typeKeyDirectory = typeKeyDirectory;
 }
Beispiel #9
0
 public CommandController(ICommandDispatcher commandDispatcher, TypeKeyDirectory typeKeyDirectory)
 {
     this.commandDispatcher = commandDispatcher;
     this.typeKeyDirectory  = typeKeyDirectory;
 }
 public EventSourcingRepository(IEventStorage <TAggregate> eventStorage, ISnapshotStorage <TAggregate> snapshotStorage, IEventDispatcher eventDispatcher, TypeKeyDirectory typeKeyDirectory, Factory <TAggregate> aggregateFactory)
 {
     this.eventStorage     = eventStorage;
     this.snapshotStorage  = snapshotStorage;
     this.eventDispatcher  = eventDispatcher;
     this.typeKeyDirectory = typeKeyDirectory;
     this.aggregateFactory = aggregateFactory;
 }
Beispiel #11
0
 public Command WithTypeKeyDirectory(TypeKeyDirectory typeKeyDirectory) => AsCommand(typeKeyDirectory[PayloadKey]);