Hi,
I'm looking for some advice for the following.
I need to create a DAL that is interchangeable between a database and a webservice. I'm developing in C# and WPF.
has anyone see any good implementations of an IUnitOfWork and allows different DAL to be switch in or out using some sort of DI?
EDIT
So after doing some reading. I've decided to use a Repository Pattern. The Rep Pattern takes in a IUnitOfWork. Above reads the opposite way around. Also here is an example for what i mean with the switch in or out.
NHibernateProductRepository : IRepository<Product>
{
private IUnitOfWork _unitOfWork = null;
public NHibernateProductRepository(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
}
WebServiceProductRepository : IRepository<Product>
{
private IUnitOfWork _unitOfWork = null;
public WebServiceProductRepository (IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
}
....
public static class Bootstrapper
{
public static void Load()
{
// Some sort of IOC.. Which will also be used for DI.
}
}
So I guess I need help with the IUnitOfWork stuff. The Web Service Repositories are going to be tricky. So how do I create some sort of transaction, and how do I queue etc etc.
One last thing, in a WPF environment multiple threads could be saving things to the database, so for each thread should it create it's own UnitOfWork? I'm scared a thread could commit half way through another etc.