Unit of work
You might argue that we do not need unit of work in the previous situation as we are only saving a single entity using one call to ISession.Save
. But remember that saving an employee instance results in multiple database records being inserted, and ideally, the whole operation of inserting these multiple records in database should be an atomic operation. Unit of work guarantees the atomicity we need. Before we bring a notion of unit of work, I would like to spend some time talking about scope of unit of work in this particular situation. A unit of work has to begin somewhere and end somewhere. Determining where unit of work begins and ends is crucial to robustness of data access layer.
Scope of unit of work for web applications
Web application design is an interesting topic. This book is not on web application design hence I will not spend too much time on it. But there is one aspect of web application design that is critical in deciding the scope of unit of work. Is your web...