将此逻辑放入存储库或服务中

时间:2013-03-12 16:39:16

标签: c# repository-pattern service-layer

我应该将此方法放入我的ISchoolclassCodeRepository还是我的ISchoolclassService?

/// <summary>
        /// The client passes newly created and existing schoolclass codes.
        /// The newly created schoolclass codes are returned.
        /// </summary>
        /// <param name="newAndExistingSchoolclassCodes">All schoolclass codes and the newly created by the user</param>
        /// <param name="schoolyearId">The related schoolyear for a schoolclass code</param>
        /// <returns>The newly created schoolclass codes</returns>
        public IEnumerable<SchoolclassCode> GetNewCreatedSchoolclassCode(IEnumerable<SchoolclassCode> newAndExistingSchoolclassCodes, int schoolyearId)
        {
            var existingSchoolclassCodes = _uniOfWork.SchoolclassCodeRepository.GetSchoolclassCodes(schoolyearId).ToList();
            var newSchoolclassCodes = existingSchoolclassCodes.Except(newAndExistingSchoolclassCodes,new SchoolclassCodeComparer());
            return newSchoolclassCodes;
        }

2 个答案:

答案 0 :(得分:0)

我的投票将是ISchoolclassService,如果你有的话。但是,我不会为此目的创建一个。

这还取决于SchoolclassCodeComparer的作用。如果它拥有自己的数据访问权限,那么它将调用相同的存储库来获取学校代码吗?

如果有一种方法可以将SchoolclassCodeComparer强加的约束传递给查询,那么我会在存储库中有这个。使用各种规则对结果集进行后处理可以驻留在服务中。

我更喜欢让存储库层处理DataAccess。 Dataaccess中的逻辑将仅限于构造参数,并创建返回结果的投影(如果需要)。

基于任何其他业务逻辑对数据集进行按摩/过滤可能是服务的工作。

答案 1 :(得分:0)

这似乎更像是应用程序逻辑,在您的情况下,这将在您的服务中实现。但是,这通常会进入应用程序层。 Here's some more information解释了各个层次,也许你想采用其中的一些概念。

存储库只保存数据访问逻辑:这意味着类似CRUD的操作。

相关问题