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); }
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(); } }
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); }