I'm changing the architecture of an enterprise accounting application. i'm going to use the IRepositoy<TDataModel> pattern but with a little difference. i'm going to make an interface for every entity which derives from the base IRepository<TDataModel>. for example if my entities were Client,Product and Order then i would have
IClientRepository : IRepository<ClientModel>
IProductRepository : IRepository<ProductModel>
IOrderRepository : IRepository<OrderModel>
public interface IRepository<TDataModel, TId>
{
TDataModel Get(TId Id);
IList<TDataModel> List();
TDataModel Add(TDataModel Item);
TDataModel Add(TDataModel Item, IContext executingContext);
void Update(TDataModel Item);
void Update(TDataModel Item, IContext executingContext);
bool Delete(TId Id);
bool Delete(TId Id, IContext executingContext);
IList<TDataModel> Where
(System.Linq.Expressions.Expression<Func<TDataModel, bool>> criteria);
}
public interface IProductRepository : IRepository<DataModel.Product, int>
{
}
the reason for using this approach is i want to set some domain model's attributes in DAL and not in BLL - for example setting CreationDate of some entities (BTW is it right to do ?)
i saw some IRepository<> samples but couldn't find anything which use this combination. i want to know is there any good to do this ? is it right at all ? what's other pros and cons ?
thanks in advance
I guess it depends on how you think of the creation date. Is it part of the domain or not? Does any domain logic depend on the value?
For example, does the system need the ability to "create on behalf of" (in which case the creator and creation date will not be equal to the current user and current time)? Would anything break if restoring data from a backup didn't retain the original values? Does it matter to you whether the creation date is the client's timetime, server datetime or database datetime?
If the answer to all the above is NO then A) the creation date isn't part of the domain so it can be set externally B) do you really need it at all? if so, then I'm guessing only for infrastructure concerns- cache management, change notifications, etc. Is that right?