我只是完成使用Ninject依赖注入到我的asp.net网站API项目实施库模式&工作单位。的ASP.NET Web API库模式服务层(业务逻辑)
使用实体框架作为我的ORM。
我有以下soluction结构(项目):
- Web应用程序(asp.net网页API)
- 数据(的DbContext,资料库)
- 接口(IRepository等)
- 模型(来自DB的POCO类)
例如我的PersonRepository(数据项目):
public class PersonsRepository : EFRepository<Person>, IPersonsRepository
{
public PersonsRepository(DbContext context) : base(context) { }
public IQueryable<Person> GetByAge(int age)
{
return DbSet.FirstOrDefault(ps => ps.age == age);
}
public void Delete(int personId, int age)
{
// Here I want to validate some stuff before deleting
// Business Rules need to be here!!
var attendance = new Attendance {PersonId = personId, Age = age};
Delete(attendance);
}
}
所以我的问题是,如果它的正确实施我的存储库方法中的所有业务逻辑?以及在需要的情况下返回消息或验证的最佳方式是什么。
谢谢,感谢任何帮助!
其实我参考了John Papa Code Camper项目:https:// github。com/johnpapa/CodeCamper 在我有的示例代码中,该存储库模式是自定义存储库的自定义实现...因为GetByAge方法只会被PersonRepo使用 – VAAA
因此,您告诉我的是业务规则或逻辑(检查某些字段是否正确,如果条件为真或模型项目中的哪些内容(我拥有POCO类)? – VAAA
业务逻辑应该停留在业务逻辑层,而不是数据访问 – MikeSW