All pastes #507323 Raw Edit

Unit Of Work pattern

public text v1 · immutable
·published 2007-05-24 14:08 UTC
rendered paste body
// Assembly1
public class DomainObject
{
   protected void markDirty()
   {
      UnitOfWork.getCurrent.RegisterDirty(this);
   }
}

//Assembly1
public class UnitOfWork
{
   public void Commit()
   {
      foreach (DomainObject obj in _dirtyObjects)
      {
         IMapper mp = MapperRegistry.GetMapper(obj.GetType());
         mp.Update(obj);
      }
   }
}

// Assembly1
public interface IMapper
{
   void Update(DomainObject obj);
}

// Assembly2
public class DomainObjectMapper : IMapper
{
   public void Update(DomainObject obj)
   {
   }
}

//Assembly3
public static class MapperRegistry
{
   public static IMapper GetMapper(Type type)
   {
   }
}