In this case, I use several repositories and several UnitOfWork approaches. Suppose you have CustomerRepository and InvoiceRepository. If you need to do this:
customerRepository.Add(customer); invoiceRepository.Add(bill);
and have these two as a transaction, then what I am doing is creating a repository. I give them the same UnitOfWork as:
IUnitOfWork uow = UnitOfWork.Start(); ICustomerRepository customerRepository = new CustomerRepository(uow); IInvoiceRepository invoiceRepository = new InvoiceRepository(uow);
so the above statements:
customerRepository.Add(customer); invoiceRepository.Add(bill); uow.Commit();
All the magic is lower, depending on what you use as data technology (ORM, for example, NHibernate or maybe raw ADO.NET), and this is not recommended in most cases).
For a good example, in the repository template and UnitOfWorks, go through this tutorial , but note that you cannot activate several UnitOfWorks modules in it (and it requires several applications, which is actually so there is no real problem there). In addition, the tutorial uses NHibernate, so if you are not familiar with the concept of ORM, I suggest you enter it (if the schedule allows it).
one more thing: you also have more complex templates, such as a conversation session, etc., but this is advanced material in which I now have my own head if you want to take a look at uNhAddIns projects (for NHibernate also)
Denis biondic
source share