/// <summary>
        /// Configure DynamoDb saga repository
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configure"></param>
        public static void AddDynamoDbEventStore <TSaga>(this IServiceCollection services, Action <DynamoDbEventStoreOptions> configure = null) where TSaga : class, IEventSourcedSaga
        {
            var options = new DynamoDbEventStoreOptions();

            configure?.Invoke(options);

            var name = typeof(TSaga).Name;

            if (options.StoreName is null)
            {
                options.StoreName = $"MassTransist.DynamoDbIntegration.{name}";
            }

            services.AddSingleton(options);
            var provider = services.BuildServiceProvider();

            var knownEventTypes = provider.GetService <KnownEventTypes>();

            if (knownEventTypes is null)
            {
                throw new InvalidOperationException("Known events types should be registered before register saga repository. Consider use RegisterKnownEventsTypes(params Type[] knownEvetTypes)");
            }

            services.AddAWSService <IAmazonDynamoDB>(options);

            services.AddSingleton <IDynamoDbEventStoreDatabaseContext, DynamoDbEventStoreDatabaseContext>();
            services.AddAsyncInitializer <DynamoDbEventStoreDatabaseContextInitializer>();

            var client     = services.BuildServiceProvider().GetService <IAmazonDynamoDB>();
            var repository = new DynamoDbSagaRepository <TSaga>(new DynamoDBContext(client), options, knownEventTypes);

            services.AddSingleton <DynamoDbSagaRepository <TSaga> >(repository);
        }
コード例 #2
0
        public StateMachineSpecs(DynamoDbEventStoreFixture fixture)
        {
            _knownEventTypes = new KnownEventTypes();
            _knownEventTypes.RegisterTypes(typeof(ProcessStarted), typeof(ProcessStopped), typeof(SomeStringAssigned));

            _fixture = fixture;
            _sagaId  = Guid.NewGuid();

            _harness    = new InMemoryTestHarness();
            _repository = new DynamoDbSagaRepository <Instance>(_fixture.Connection, _fixture.Options, _knownEventTypes);
            _machine    = new TestStateMachine();
            _saga       = _harness.StateMachineSaga(_machine, _repository);

            TaskUtil.Await(StartHarness);
        }