Service - Business Layer

Service are business layer which handles all logic and business of our applications.

Like repository, each service should be implemented as a OOP class with a singleton instance.

Unfortunately, eslint-plugin-react-hooks misunderstands the class implementation of a service with React custom hooks that class implementation violates Rules of Hooks, we should implement a service as a prototype-based object. You might want to use Typescript interface to archieve OOP features (polimorphism, abstraction, …)

Service should call repositories to get data, handle them to send to presentation layer.

For example:

export interface AppService {
  useTitle(title: string);
}

export const appService = {
  useTitle(title: string) {
    React.useEffect(
      () => {
        document.title = title;
      },
      [title],
    );
  }
}