Fixed usage of CreateIndexes for mongo #1287
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #1250