I am developing an app in DDD manner. And I have a little problem with it.I have a Fare (airline fare) and FareRepository objects. And at some point I should load additional fare information (from a server, call server api) and setup this information to existing Fare.I guess that I need to create an Application Service (FareAdditionalInformationService) that will deal with obtaining data from the server and than update existing Fare or put the business logic in Fare object. However, some people said me that it is necessary to use FareRepository for this problem. I don't know wich place is better for my problem Service or Repository.UPDATE:After researching, I came to the conclusion, that the better place for fetching additional Fare information is a service like (AdditionalFareService).The code would look something like this://create service for fetching fare informationAdditionalFareService service = new AdditionalFareService();//get a fare by IdFare fare = fareRepository.GetById(myFareId);//Obtain information from servicevar fareInformation=service.getAdditionalInformation(fare)//Add it to the fare.fare.AddInformation(fareInformation);//save it to the repository.fareRepository.Save(fare);
DDD: Service or Repository
design patterns;object oriented;architecture;domain driven design
I'm assuming that the FareInformation provides details about a given Fare (e.g. special terms and conditions, change fees, etc.)You need a way to create and save a FareInformation in order to associate it with the Fare. In this case, I'd say provide methods on the Fare that does it for you.The API would look something like this//get a fare by IdFare fare = fareRepository.GetById(myFareId);//Create a change fee object.var fareInformation=new ChangeFee(new UsdCurrency(50.00d))//Add it to the fare.fare.AddInformation(fareInformation);//save it to the repository.fareRepository.Save(fare);Note that I'm sending a ChangeFee object and not a FareInformation object. FareInformation is a base class in a hierarchy. I'm relying on the O/RM to map the hierarchy to a database structure for me.