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.

Is it ok to call a webservice from a Domain object?.

As I write the question I am thinking that you should never do that, as it is poor design, but the situation is the following:

I have a domain object called Postman that works very closely with a Message object. This Message is provided by a web service. Without the Message, the Postman object could not do its business logic.

I understand that this code doesn't smell good but, since the Postman depends on the Message, it seems logical to call the web service in order to get the Message.

There is no other way to get the Message without the web service.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

What would you do if the message was in a database? Do the exact same thing. A web service is just another storage device, in essence.

Your calling code should know nothing of the repository implementation details, if at all possible. Database, text file, web service, it's all GetMessage().

share|improve this answer

Just abstract the web service into a domain service and encapsulate it inside an implementation. That is why services in DDD exist. To abstract and encapsulate the outside world.

share|improve this answer

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.