IRepository和每个实体的存储库
我正在更改企业会计应用程序的体系结构。我将使用 IRepositoy
IClientRepository : IRepository
IProductRepository : IRepository
IOrderRepository : IRepository
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>
{
}
使用这种方法的原因是我想在 DAL 中设置一些域模型的属性,而不是在 BLL 中 - 例如设置某些实体的 CreationDate (顺便说一句,这样做是否正确?)
我看到了一些 IRepository<>样本,但找不到任何使用此组合的东西。我想知道这样做有什么好处吗?这到底是对的吗?还有什么其他优点和缺点?
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想这取决于您如何看待创建日期。它是否是域的一部分?任何域逻辑是否依赖于该值?
例如,系统是否需要“代表创建”的能力(在这种情况下,创建者和创建日期将不等于当前用户和当前时间)?如果从备份恢复数据没有保留原始值,会出现什么问题吗?创建日期是客户端时间、服务器日期时间还是数据库日期时间对您来说重要吗?
如果以上所有问题的答案都是“否”,那么
A)创建日期不是域的一部分,因此可以在外部设置
B)你真的需要它吗?如果是这样,那么我猜测只是出于基础设施问题——缓存管理、更改通知等。对吗?
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?