azure-cosmos-dotnet-repository icon indicating copy to clipboard operation
azure-cosmos-dotnet-repository copied to clipboard

InMemoryRepository has different implementations per interface

Open mumby0168 opened this issue 2 years ago • 4 comments

Given you are using the in-memory repository implementation and you make use of the new types IWriteOnlyRepository<T> and IReadOnlyRepository<T> if you resolve them both for the same TItem then say write to using the write-only interface then try and read using the read-only version, then the result will not be found.

I think this is due to the fact that these are registered with a different instance of an InMemoryRepository<T> per interface.

https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/3a3be6b61f88732cc653fd334211c83205b23cc8/src/Microsoft.Azure.CosmosRepository/Extensions/ServiceCollectionExtensions.cs#L97-L113

I think we are best off refactoring the in-memory imp to have a shared store of events that all interfaces can use and interact with.

mumby0168 avatar Mar 22 '22 21:03 mumby0168

That makes sense. I always thought that for testing we would have just use a static ConcurrentDictionary.

IEvangelist avatar Mar 23 '22 01:03 IEvangelist

A static dictionary would work but if we want to really improve the in memory implementation we should consider implementing some services that store manipulate the data (serialisation/deserialization and etags/ttl/ts) moving some of the storage logic out. This would let us work towards a more realistic implementation.

robennett2 avatar Mar 24 '22 18:03 robennett2

A static dictionary would work but if we want to really improve the in memory implementation we should consider implementing some services that store manipulate the data (serialisation/deserialization and etags/ttl/ts) moving some of the storage logic out. This would let us work towards a more realistic implementation.

I like it and I agree. How much effort would it take?

IEvangelist avatar Mar 28 '22 12:03 IEvangelist

It could be a fair bit, it depends how far we want to go. I have started fleshing out a basic implementation. With what is there (and a little extra work) we could fix this bug. Then the framework is there to extend and clean it up. I have raised a POC that I will keep working on. Hopefully will get some time this weekend to take a look.

https://github.com/IEvangelist/azure-cosmos-dotnet-repository/pull/268

robennett2 avatar Mar 31 '22 21:03 robennett2