Skip to content

Services

Dani Donisa edited this page Jul 20, 2023 · 6 revisions

Problem

You have a complex set of operations that need to be executed in a sequence synchronously or asynchronously.

Solution

Concentrate the core logic of a request operation into a service class which resides under src/api/app/services.

Details

Services can easily become a code smell if not handled properly. If you find yourself with a service that has too many methods and/or becomes generally unreadable and hard to understand, you might have to find a bounded context or use one of the design patterns mentioned in that article.

Implementation

  • Each service should do only one thing.
  • Name a service after what they do: if a service creates event subscriptions, then EventSubscriptionCreator would be a good name.
  • The main entry point for a service is the call method, with no parameters. All parameters should come via the constructor.

Links:

Clone this wiki locally