Thinking About The Repository API

time to read 4 min | 680 words

I'm currently building the API for the my Repository interface (I talked about it here). Here is what I have so far:

(Image from clipboard).png

Couple of things to note, I don't have Delete or Save methods, instead, I use RegisterSave() and RegisterDelete(), both of those make it clearer that a Unit Of Work is in action here. To make it more explicit (and to allow several repositories to use in a single Unit Of Work, I made the Unit Of Work an explicit concept:

(Image from clipboard).png

A sample code using this framework will look like this:

using (UnitOfWork.Start())




        Customer customer = Repository<Customer>.Load(15);

        Order order = new Order();





Looking at the code, I don't know if RegisterSave() gives anything, to tell you the truth.

I'm using the commit only flush mode with NHibernate, which mean that if you are not commit the transaction, it will not be saved to the database. The problem is that then all my writing to the database will be inside a With.Transaction() block, which mostly make the Register***() mote.