danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.39k stars 1.2k forks source link

Fixed usage of CreateIndexes for mongo #1287

Closed agentschmitt closed 1 week ago

agentschmitt commented 3 months ago

Describe the change Fixed usage of CreateIndexes for MongoPersistenceProvider.cs to avoid database connection already opening during ioc. Doing database operations in constructor of services that are registered in ioc is dangerous. In case of connection error the application will crash during ioc already.

Describe your implementation or design I checked how EntityFrameworkPersistenceProvider does database changes and its done in EnsureStoreExists there. https://github.com/danielgerlag/workflow-core/blob/master/src/providers/WorkflowCore.Persistence.EntityFramework/Services/EntityFrameworkPersistenceProvider.cs#L192

Tests I adjusted the MongoPersistenceProviderFixture to call EnsureStoreExists like its done for the other Providers too.

Breaking change Change should be minor, as EnsureStoreExists is already used from workflow-core for other providers.

Additional context Some of the mongo unit tests do not execute, but this was already the case before my change. This is probably cause of the mongodb driver update from 2.8 to 2.19 https://www.mongodb.com/docs/drivers/csharp/v2.19/faq/#what-object-types-can-be-serialized- There is already in issue for this https://github.com/danielgerlag/workflow-core/issues/1250