8

Does it correct way to have two repository inside one service and will it be an application or domain service?

Suppose I have a Passenger object that should contains Passport (government id) object. I am getting Passenger from PassengerRepository. PassengerRepository create request to server and obtain data (json) than parse received data and store inside repository.

I have confused because I want to store Passport as Entity and put it to PassportRepository but all information about password contains inside json than i received above.

I guess that I should create a PassengerService that will be include PassengerRepository and PassportRepository with several methods like removePassport, addPassport, getAllPassenger and etc.

UPDATE:

So I guess that the better way is represent Passport as VO and store all passports inside Passenger aggregate. However there is another question: Where I should put the methods (methods calls server api) for management passenger's passport. I think the better place is so within Passenger aggregate.

7

It's not unheard of for a service to have two repositories, but it is often a hint of a poor design. It's worth looking at, to see if you could improve your design but, if you look and you can't improve it, you shouldn't worry too much.

In your case, I think you need to look at the concept of Aggregates in DDD.

Aggregates are groups of things that belong together. An Aggregate Root is the thing that holds them all together.

If Passenger and Passport don't belong together, I don't know what does. Your aggregate root in this case should obviously be Passenger.

  • Yeah I know about Aggregates for sure. Ok if a Passenger is Aggregate and contains all of passenger passport, where I should put the methods (methods calls server api) for adding or removing passports, inside Passenger object? – tikhop Nov 7 '12 at 14:16
  • @tikhop: Hard to know for sure without being in your code, but I'd imagine so, yes. – pdr Nov 7 '12 at 14:39
0

I'm in total agreement with @pdr that you don't need to blame yourself because of an additional repository in your service.

About the passport methods, such as addPassport, I think they should stay in PassengerService and in Passport Repository. Something like:

public class PassengerService : ServiceBase<Passenger>, IPassengerService {

    private readonly IPassportRepository _passport_repository;
    private readonly IPassengerRepository _pass_repository

    public PassengerService(IPassportRepository passport_repository,     IPassengerRepository passenger_repository) {
        ...

    }


   public void removePassport(...) {
       _passport_repository.remove(...);

   }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.