Skip to content

MongoDB constraint (AggregateId + AggregateSequenceNumber) not created #1095

@Luuck4s

Description

@Luuck4s

I'm using EventFlow with MongoDB, and I noticed that the constraint (AggregateId + AggregateSequenceNumber) is not being created.

After checking the source code, I found that other database implementations like MySQL and PostgreSQL create this constraint directly via the initialization scripts.

However, for MongoDB, there is a method called Initialize() that appears to be responsible for setting up this constraint, but it doesn't seem to be called anywhere.

Is this intentional, or is it possibly a bug?

Image

Suggestions for a fix:

In EventFlowOptionsMongoDbEventStoreExtensions.cs:

        public static IEventFlowOptions UseMongoDbEventStore(this IEventFlowOptions eventFlowOptions)
        {
            eventFlowOptions.UseEventPersistence<MongoDbEventPersistence>();
            eventFlowOptions.ServiceCollection
                .TryAddTransient<IMongoDbEventPersistenceInitializer, MongoDbEventPersistenceInitializer>();
          
           // Add this block of code
            using var serviceProvider = eventFlowOptions.ServiceCollection.BuildServiceProvider();
            var initializer = serviceProvider.GetRequiredService<IMongoDbEventPersistenceInitializer>();
            initializer.Initialize();

            return eventFlowOptions;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions