开发者

Where IdentityMap belongs: UnitOfWork or Repository?

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 开发者_JS百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜