Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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