If I implement some simple OR/M tool, where do I put identity map? Obviously, each Repository should have access to its own identity map, so it can register loaded objects (or maybe DataMapper is the one who registers objects in IdentityMap?).

And when I commit unit of work, I also need to access the identity map to see which entity is dirty and which is clean (or I am wrong again and there is some outer object which calls RegisterClean/RegisterDirty methods of my UnitOfWork class? Then what object does this?).

Does this mean that I should implement IdentityMap as a completely independent object which contains inner IdentityMaps for each entity type?

Really confused about how IdentityMap, Repository and UnitOfWork work all together.

Was it helpful?


With our .NET O/R Mapper, LightSpeed we placed the identity map inside the unit of work class. This has worked very well for us and feels quite natural as it effectively acts as a level 1 cache for querying purposes during the unit of work's life.

Generally, inject or somehow provide a UoW for your Repository class so that you have an effective scope and gateway to querying.

I hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow