Ejemplo n.º 1
0
        private void ReadModels()
        {
            // Should match with RecreateReadModelContext.
            DefaultQueryDispatcher queryDispatcher = new DefaultQueryDispatcher();

            QueryDispatcher = queryDispatcher;

            CategoryBuilder categoryBuilder = new CategoryBuilder();

            queryDispatcher.AddAll(categoryBuilder);
            eventDispatcher.Handlers.AddAll(categoryBuilder);

            OutcomeBuilder outcomeBuilder = new OutcomeBuilder(PriceFactory);

            queryDispatcher.AddAll(outcomeBuilder);
            eventDispatcher.Handlers.AddAll(outcomeBuilder);
        }
Ejemplo n.º 2
0
        public void Queries()
        {
            IQueryHandlerCollection collection = new DefaultQueryDispatcher();

            collection.AddAll(new Q1Handler());

            IQueryHandler <Q1, R1> handler1;

            Assert.AreEqual(true, collection.TryGet(out handler1));
            IQueryHandler <Q2, R2> handler2;

            Assert.AreEqual(true, collection.TryGet(out handler2));

            collection.AddAll(new Q2Handler());

            IQueryHandler <Q3, R3> handler3;

            Assert.AreEqual(true, collection.TryGet(out handler3));
            IQueryHandler <Q4, R4> handler4;

            Assert.AreEqual(true, collection.TryGet(out handler4));
        }
Ejemplo n.º 3
0
        private void Domain()
        {
            Converts.Repository
            .AddStringTo <int>(Int32.TryParse)
            .AddStringTo <bool>(Boolean.TryParse)
            .AddEnumSearchHandler(false)
            .AddJsonEnumSearchHandler()
            .AddJsonPrimitivesSearchHandler()
            .AddJsonObjectSearchHandler()
            .AddJsonKey()
            .AddJsonTimeSpan()
            .Add(new ColorConverter())
            .AddToStringSearchHandler();

            eventStore      = new EntityEventStore(eventSourcingContextFactory);
            eventDispatcher = new PersistentEventDispatcher(new EmptyEventStore());
            eventDispatcher.DispatcherExceptionHandlers.Add(exceptionHandlerBuilder);
            eventDispatcher.EventExceptionHandlers.Add(exceptionHandlerBuilder);

            IFactory <ICompositeStorage> compositeStorageFactory = Factory.Default <JsonCompositeStorage>();

            typeProvider = new ReflectionCompositeTypeProvider(
                new ReflectionCompositeDelegateFactory(),
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public
                );

            commandFormatter = new CompositeCommandFormatter(typeProvider, compositeStorageFactory);
            eventFormatter   = new CompositeEventFormatter(typeProvider, compositeStorageFactory, new List <ICompositeFormatterExtender>()
            {
                new UserKeyEventExtender()
            });
            queryFormatter     = new CompositeListFormatter(typeProvider, compositeStorageFactory, logFactory);
            exceptionFormatter = new CompositeExceptionFormatter(typeProvider, compositeStorageFactory);

            commandDispatcher = new PersistentCommandDispatcher(new SerialCommandDistributor(), new EmptyCommandStore(), commandFormatter);
            commandDispatcher.DispatcherExceptionHandlers.Add(exceptionHandlerBuilder);
            commandDispatcher.CommandExceptionHandlers.Add(exceptionHandlerBuilder);

            queryDispatcher = new DefaultQueryDispatcher();

            var outcomeRepository = new AggregateRootRepository <Outcome>(
                eventStore,
                eventFormatter,
                new ReflectionAggregateRootFactory <Outcome>(),
                eventDispatcher,
                new NoSnapshotProvider(),
                new EmptySnapshotStore()
                );

            var categoryRepository = new AggregateRootRepository <Category>(
                eventStore,
                eventFormatter,
                new ReflectionAggregateRootFactory <Category>(),
                eventDispatcher,
                new NoSnapshotProvider(),
                new EmptySnapshotStore()
                );

            var currencyListRepository = new AggregateRootRepository <CurrencyList>(
                eventStore,
                eventFormatter,
                new ReflectionAggregateRootFactory <CurrencyList>(),
                eventDispatcher,
                new NoSnapshotProvider(),
                new EmptySnapshotStore()
                );

            Money.BootstrapTask bootstrapTask = new Money.BootstrapTask(
                commandDispatcher.Handlers,
                Factory.Instance(outcomeRepository),
                Factory.Instance(categoryRepository),
                Factory.Instance(currencyListRepository)
                );

            bootstrapTask.Initialize();

            UserHandler userHandler = new UserHandler(services.BuildServiceProvider().GetRequiredService <UserManager <ApplicationUser> >(), eventDispatcher);

            commandDispatcher.Handlers.AddAll(userHandler);
            queryDispatcher.AddAll(userHandler);
        }