I'm trying to design a well defined yet simple interface for the unit of work and repository patterns. My UoW's are exposed to services and services then "get repositories" that it needs to query. I know returning IQueryable<T> for repositories is a religious war. Because repositories are only exposed to the service, all queries are performed inside the service and therefore I can test the queries. Is there anything I should change for these interfaces? All criticisms are greatly appreciated!
public interface IUnitOfWork : IDisposable
{
bool IsActive { get; }
bool WasCommitted { get; }
/// <summary>
/// Commits all changes made on the unit of work.
/// </summary>
void Commit();
bool WasRolledBack { get; }
/// <summary>
/// Rolls back all changes made on the unit of work.
/// </summary>
void Rollback();
/// <summary>
/// Returns an instance of an entity with the specified key that is attached to the unit of work without
/// loading the entity from a repository.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T Load<T>(int id)
where T : class;
void Attach<T>(T entity)
where T : class, IIdentifiable;
void Detach<T>(T entity)
where T : class;
IRepository<T> GetRepository<T>()
where T : class;
}
public interface IRepository<T>
where T : class
{
IUnitOfWork UnitOfWork { get; }
void Add(T entity);
void Remove(T entity);
/// <summary>
/// Returns an instance of an entity with the specified key that is attached to the unit of work by loading
/// the entity from the repository.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T Get(int id);
IQueryable<T> All();
}