Filters in DDD Repository

前端 未结 4 1104
遥遥无期
遥遥无期 2021-02-03 12:01

There is Campaign Entity and for that, I have CampaignRepository which have this functions

  1. public IList FindAll();
  2. public Campaign FindByCampaignNumber(st
4条回答
  •  离开以前
    2021-02-03 12:28

    Here is how I would do this:

    class Campaigns{
      IEnumerable All(){...}
      IEnumerable ByNumber(int number){...}
      IEnumerable CreatedToday(){...}
      IEnumerable CreatedThisMonth(){...}
      IEnumerable CreatedThisYear(){...}
      IEnumerable Latest5(){...}
    
      private IQueryable GetSomething(Something something){
        //used by public methods to dry out repository
      }
    }
    

    Reasoning is simple - it matters by what You are interested to look for campaigns (that knowledge is part of Your domain). If we explicitly state functions to reflect that, we will always know it.


    Is it appropriate to add all this methods in campaign repository ?

    I don't see anything wrong with that.

    Arnis i want some code, how u implementing Created today function in domain itself, Are you injecting repository here in this function ? Thanks for your cooperation

    I wouldn't implement CreatedToday function in my domain. It would sit in repository and repository implementations should not be concern of domain. If You mean how I would use Campaign repository and if it should be used from domain - no, it should not be used from within of domain. If You mean if I would inject repository inside of repository - You are listening too much of xzibit.

提交回复
热议问题