Event sourcing Integration Testing with InMemoryRepository fails due to Problems with Dependency Injection #287
Labels
bug
Something isn't working
event-sourcing
Related to the CosmosEventSourcing project.
help wanted
Extra attention is needed
up-for-grabs 🙏🏽
Happy to consider a pull review to address this issue
Projects
Describe the bug
I have a ASP.NET project where I use the Event Sourcing functionality from this SDK. Now I want to use the InMemoryRepository for Integration Testing of my project. But I have identified several problems when I try to do this. But in this bug, I will only care about the two related to Dependency Injection of the InMemoryRepository in the DefaultEventStore constructor.
Problem 1
DefaultEventStore.Def.cs injects two repositories in the constructor IBatchRepository and IReadOnlyRepository.
Only IReadOnlyRepository<> is registered when calling builder.Services.AddInMemoryCosmosRepository();.
This causes problems where DefaultRepository is used for writes and InMemoryRepository is used for reads in DefaultEventStore.
This can easily be solved by adding : (to src/Microsoft.Azure.CosmosRepository/Extensions/ServiceCollectionExtensions.cs AddInMemoryCosmosRepository method )
Problem 2
The DI service will now create two different instances of InMemoryRepository when creating DefaultEventStore after we have applied the fix from Problem 1. This will again give problem that we cannot read what we write in the DefaultEventStore. This will directly generate problems related to the AtomicEvent Etag.
The simplest way to fix this is to rewrite the constructor in src/Microsoft.Azure.CosmosEventSourcing/Stores/DefaultEventStore.Def.cs from
to
Notes
With my proposal for fix Problem 2, the fix from Problem 1 will be in relevant in this case, but I think that should be fixed anyway.
Related issue: #266
Environment summary
SDK Version: latest main branch
OS Version: Windows
Additional context
Program.cs
The text was updated successfully, but these errors were encountered: