Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why shouldn't a service call other services? One Service may extend the features e.g. network < encryption < http.


Three reasons:

First: we found that it creates a spider web of dependencies if we din't have this rule. Instead, if you return control to the controller after performing a discrete action, it makes sure that business logic stays out of services and keeps service functions short and directed.

Second: it makes it easy to keep the entire design in your head.

Third: It promotes composition. This leads to easier testability with mocks rather than having to resort to full blown integration tests for even the smallest things. (We still do integration tests, but mock tests can be churned out in volume and are less fragile).


I don’t think the comment implies that a service can’t be layered.


Yes. So something like a "DatabaseService" might have a database connection, which is code we don't own. But the code we do own stops at that layer. This prevents a spider web of dependencies opening up.


layering is just a stronger agreement compared to composition imho.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: