Пример #1
0
        public void Run()
        {
            var sut = new QueryPipeline(loadContext, processQuery);

            var result = sut.Handle(new MyQuery {
                Prefix = ":"
            });

            Assert.Equal(":foo", ((MyQueryResult)result.Msg).Value);
            Assert.Empty(result.Notifications);


            (IMessageContextModel Ctx, string Version) loadContext(IMessage msg)
            {
                return(new MyQueryCtx {
                    Value = "foo"
                }, "");
            }

            QueryResult processQuery(IMessage msg, IMessageContextModel ctx)
            {
                return(new MyQueryResult {
                    Value = (msg as MyQuery).Prefix + (ctx as MyQueryCtx).Value
                });
            }
        }
Пример #2
0
 public Session(
     LoadPipeline loadPipeline,
     QueryPipeline queryPipeline,
     CommitPipeline commitPipeline,
     QueryFactory queryFactory,
     IIdManager idManager,
     IIdAccessor idAccessor,
     ITrackingProvider tracking,
     ISessionCache sessionCache
     )
 {
     _sessionCache   = sessionCache;
     _loadPipeline   = loadPipeline;
     _queryPipeline  = queryPipeline;
     _commitPipeline = commitPipeline;
     _queryFactory   = queryFactory;
     _idManager      = idManager;
     _idAccessor     = idAccessor;
     _tracking       = tracking;
 }
Пример #3
0
        /// <summary>
        /// Demo init.
        /// </summary>
        private static void Init()
        {
            Paging.Try1();

            /*
             * var config = Saritasa.Tools.Messages.Configuration.XmlConfiguration.AppConfig;
             * CommandPipeline = (ICommandPipeline)config.First();
             */

            // We will use in memory repository.
            inMemoryMessageRepository = new InMemoryMessageRepository();

            // Create command pipeline manually.
            CommandPipeline = new CommandPipeline();
            CommandPipeline.AddMiddlewares(
                new CommandValidationMiddleware(),
                new CommandHandlerLocatorMiddleware(Assembly.GetEntryAssembly()),
                new CommandHandlerExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );

            // Create query pipeline manually.
            QueryPipeline = new QueryPipeline();
            QueryPipeline.AddMiddlewares(
                new QueryObjectResolverMiddleware(),
                new QueryExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );

            // Create event pipeline manually.
            EventPipeline = new EventPipeline();
            EventPipeline.AddMiddlewares(
                new EventHandlerLocatorMiddleware(Assembly.GetEntryAssembly()),
                new EventHandlerExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );
        }
Пример #4
0
        public Settings2(string databaseName, Connection connection, ILogger logger = null)
        {
            Logger = logger ?? new NullLogger();

            //global
            IdAccessor       = new IdAccessor();
            IdManager        = new ShortGuidIdManager();
            RevisionAccessor = new RevisionAccessor();
            TypeManager      = new TypeManager();

            Serializer = new Serializer(IdAccessor, RevisionAccessor);

            //query serializer
            var settings = new JsonSerializerSettings()
            {
                TypeNameHandling  = TypeNameHandling.None,
                NullValueHandling = NullValueHandling.Ignore,
                ContractResolver  =
                    new CamelCasePropertyNamesContractResolver()
                {
                    NamingStrategy = new LocalCamelCaseNamingStrategy(true)
                }
            };

            settings.Converters.Add(new OrderEnumConverter());
            QuerySerializer = new Serializer(settings);

            CouchDb                = new CouchDb(databaseName, connection, Serializer, QuerySerializer, Logger);
            QueryFactory           = new QueryFactory(TypeManager, IdAccessor);
            TransactionCoordinator = new TransactionCoordinator(CouchDb, IdAccessor, RevisionAccessor);

            LoadPipeline   = new LoadPipeline(CouchDb, IdManager, IdAccessor, RevisionAccessor);
            CommitPipeline = new CommitPipeline(CouchDb, IdManager, RevisionAccessor, TransactionCoordinator);
            QueryPipeline  = new QueryPipeline(CouchDb, IdManager, IdAccessor, RevisionAccessor);

            Hash = new ToLowerPassThroughHash();
        }
Пример #5
0
 public static IServiceCollection RegisterQueryWithPipeline <TQuery, THandler, TResponse>(this IServiceCollection services, QueryPipeline <TQuery, TResponse> pipeline)
     where TQuery : IQuery <TResponse>
 {
     services.AddTransient(typeof(IQueryHandler <TQuery, TResponse>), typeof(THandler));
     services.Decorate(typeof(IQueryHandler <TQuery, TResponse>), (obj, provider) => pipeline(obj, provider));
     return(services);
 }
Пример #6
0
 public void Register <TMessage>(LoadContextModel load, ProcessQuery processQuery, UpdateContextModel update)
 {
     _broadcast.Subscribe(update);
     _pipelines[typeof(TMessage)] = new QueryPipeline(load, processQuery);
 }