Exemplo n.º 1
0
        public async Task Send <T>(ConsumeContext <T> context, IPipe <SagaRepositoryContext <TSaga, T> > next)
            where T : class
        {
            using var session = _documentStore.DirtyTrackedSession();

            var sagaRepositoryContext = new MartenSagaRepositoryContext <TSaga, T>(session, context, _factory);

            await next.Send(sagaRepositoryContext).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task <T> Execute <T>(Func <SagaRepositoryContext <TSaga>, Task <T> > asyncMethod, CancellationToken cancellationToken)
            where T : class
        {
            var session = _documentStore.OpenSession();

            try
            {
                var repositoryContext = new MartenSagaRepositoryContext <TSaga>(session, cancellationToken);

                return(await asyncMethod(repositoryContext).ConfigureAwait(false));
            }
            finally
            {
                session.Dispose();
            }
        }
Exemplo n.º 3
0
        public async Task SendQuery <T>(ConsumeContext <T> context, ISagaQuery <TSaga> query, IPipe <SagaRepositoryQueryContext <TSaga, T> > next)
            where T : class
        {
            using var session = _documentStore.DirtyTrackedSession();

            var repositoryContext = new MartenSagaRepositoryContext <TSaga, T>(session, context, _factory);

            IReadOnlyList <TSaga> instances = await session.Query <TSaga>()
                                              .Where(query.FilterExpression)
                                              .ToListAsync().ConfigureAwait(false);


            var queryContext = new LoadedSagaRepositoryQueryContext <TSaga, T>(repositoryContext, instances.ToList());

            await next.Send(queryContext).ConfigureAwait(false);
        }