dnsdurham/RefactoringSamples — pull request #2 by icotting (2014-03-23 03:17:50+00:00)
Title: Billing refactored.v2

I updated this project with two commits. The first refactors the projects to use a ServiceLocator to provide the values for engines, managers, and factories. The ServiceLocator uses a Unity IoC container to actually resolve the requested instances. In theory, this would negate the factory as the ServiceLocator could be used in its place in the managers and engines. I left that in, however, just to be consistent.

The second commit adds the concept of a unit of work. Since there wasn't anything in the project that was transactional and would necessitate a unit of work, I added a generic repository to manage an EntityFramework DbContext. I don't actually use that anywhere in the code as there is no need to persist the two DTOs, but this should give you an idea of how you would include a unit of work. If, for example, there were calls in a service or object down the call stack that would persist data, the parent caller (a controller or manager) would first get a UnitOfWork from the service locator and would then call Commit() on that unit to actually commit the various transactional resources. In this case, that would be the DbContext. The unit of work could also manage Sql connection pools or really anything that is transactional.