Unfortunately that didn't work. When the first time the cache gets hit it's ok, but the repository is still remembered because the lazy value got created at this moment. So the second cache hit doesn't force the Lazy<IRepository<Whatever>>
object to reinstantiate as the value is already there, and so the situation stays the same - "Transaction nested incorrectly", bump!:/
My dependency chain looks as follows (starting from the injection inside IShapeTableProvider implementation):
IMyManager --> IEnumerable<IMyProvider> --> IMyService (in one of the previous providers) --> IRepository<MyRecord>
I changed everything of those to Lazy<...>, as you suggested, so that every injected object is lazily instantiated. There is only one thing I cannot change - at the top, the IEnumerable<IShapeTableProvider> in DefaultShapeTableManager
looks like this
IEnumerable<Meta<IShapeTableProvider>> bindingStrategies (...)
and this collection is used inside the cached lambda. One of those providers is my provider with the chained dependencies as I wrote above. Any clues on what am I doing wrong and how to handle that?