public static void UseEntityFrameworkCoreSagaRepository(this IJobServiceConfigurator configurator, Func<JobServiceSagaDbContext> contextFactory,
            ILockStatementProvider lockStatementProvider = default)
        {
            configurator.Repository = EntityFrameworkSagaRepository<JobTypeSaga>.CreatePessimistic(contextFactory, lockStatementProvider);

            configurator.JobRepository = EntityFrameworkSagaRepository<JobSaga>.CreatePessimistic(contextFactory, lockStatementProvider);

            configurator.JobAttemptRepository = EntityFrameworkSagaRepository<JobAttemptSaga>.CreatePessimistic(contextFactory, lockStatementProvider);
        }
        public static ISagaRepository <TSaga> CreatePessimistic(ISagaDbContextFactory <TSaga> dbContextFactory,
                                                                ILockStatementProvider lockStatementProvider = null,
                                                                Func <IQueryable <TSaga>, IQueryable <TSaga> > queryCustomization = null)
        {
            var statementProvider = lockStatementProvider ?? new SqlServerLockStatementProvider();

            var queryExecutor = new PessimisticLoadQueryExecutor <TSaga>(statementProvider, queryCustomization);
            var lockStrategy  = new PessimisticSagaRepositoryLockStrategy <TSaga>(queryExecutor, IsolationLevel.Serializable);

            return(CreateRepository(dbContextFactory, lockStrategy));
        }
 public PessimisticLoadQueryExecutor(ILockStatementProvider lockStatementProvider, Func <IQueryable <TSaga>, IQueryable <TSaga> > queryCustomization)
 {
     _lockStatementProvider = lockStatementProvider;
     _queryCustomization    = queryCustomization;
 }
 public static ISagaRepository <TSaga> CreatePessimistic(Func <DbContext> dbContextFactory, ILockStatementProvider lockStatementProvider = null,
                                                         Func <IQueryable <TSaga>, IQueryable <TSaga> > queryCustomization = null)
 {
     return(CreatePessimistic(new DelegateSagaDbContextFactory <TSaga>(dbContextFactory), lockStatementProvider, queryCustomization));
 }
Beispiel #5
0
 public EntityFrameworkSagaRepositoryConfigurator()
 {
     _isolationLevel        = IsolationLevel.Serializable;
     _concurrencyMode       = ConcurrencyMode.Pessimistic;
     _lockStatementProvider = new SqlServerLockStatementProvider();
 }
Beispiel #6
0
 public EntityFrameworkTestFixture()
 {
     _testDbParameters       = new TTestDbParameters();
     DbContextOptionsBuilder = _testDbParameters.GetDbContextOptions(typeof(TDbContext));
     RawSqlLockStatements    = _testDbParameters.RawSqlLockStatements;
 }
Beispiel #7
0
        private static IServiceProvider New(Action <DbContextOptionsBuilder> configureDbContext, ILockStatementProvider lockStatementProvider = null)
        {
            var services = new ServiceCollection();

            services
            .AddLogging(logging => logging.AddConsole())
            .Configure <LoggerFilterOptions>(loggerConfig => loggerConfig.MinLevel = LogLevel.Information)
            .AddDbContext <GreetingsDbContext>(configureDbContext)
            .AddMassTransit(massTransit =>
            {
                massTransit.AddSagaStateMachine <GreetingsStateMachine, GreetingsState>()
                .EntityFrameworkRepository(entityFramework =>
                {
                    if (lockStatementProvider != null)
                    {
                        entityFramework.LockStatementProvider = lockStatementProvider;
                    }

                    entityFramework.ExistingDbContext <GreetingsDbContext>();
                });

                massTransit.UsingInMemory((context, bus) =>
                {
                    bus.ReceiveEndpoint("greetings", endpoint =>
                    {
                        endpoint.StateMachineSaga <GreetingsState>(context);
                    });
                });
            });

            return(services.BuildServiceProvider());
        }