views:

41

answers:

1

If I implement some simple OR/M tool, where do I put identity map? Obviously, each Repozitory 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, Repozitory and UnitOfWork work all together.

+2  A: 

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.

traskjd
As I understand, then if I have for example CustomerRepsitory with method GetCustomersBySurname, this will start the unit of work, because Repository itself will not be able to register object into identity map? But if my unit of work is using transactions by default, then it would not be good to start transaction when just reading data, so the UoW would need some way to see if it contains only reads and then do not start transaction. Anyway, it would be great to see a class diagram of some preferably simple OR/M tool. Somehow I cannot find any.
Martin