The 3 Tenets of Service Objects in Ruby on Rails
Rob Race
7015

Hey Rob, thanks for writing this up. We have been using SO’s for a while now, and it is always good to get other opinions on their best use.

As far as dependencies go, we typically use your second method of instantiation, where you are sending the “.call” method on the class. Then that method passes in the dependencies when it instantiates the SO, as a hash, so the signature doesn’t need to change if the dependency list changes.

This keeps all of the dependencies in one place (the class’s call method) so they are easy to see and swap out when needed. It also makes it easy to pass stubs when testing.

Show your support

Clapping shows how much you appreciated Tom Hoen’s story.