• 0 Posts
  • 5 Comments
Joined 2 years ago
cake
Cake day: July 17th, 2023

help-circle

  • How I think about repositories:
    These are simple wrappers around database calls that have few or no dependencies. If I’m adding dependencies here, then they’ll either be a cache or a logger.

    Make repositories as simple as possible, because texting them sucks. You make a repository because it makes unit testing your service easier.

    How I think about services:
    Services are just groups of related methods. In a simple CRUD API, I would typically do a service per controller and include all business logic at the service level.

    How I think about controllers:
    These should be treated like repositories and only contain logic for determining which response code to send.


  • The general idea is to not test things that need to be mocked, keep all logic out of those and keep them at the edges of the application. Then you test the remaining 90% of your code which would ideally be pure functions that don’t need mocks .

    The remaining 5% can be integration tests which doesn’t care about DI.

    In reality this doesn’t always work, because sometimes it’s better to write a complex query with logic and let your database do the processing.