# Handlers and Services

[Handlers ](https://github.com/deep-web-solutions/wordpress-framework-foundations/tree/master/src/includes/Utilities/Handlers)and [Services ](https://github.com/deep-web-solutions/wordpress-framework-foundations/tree/master/src/includes/Utilities/Services)are two distinct concepts, but they were designed together and are being used together. Specifically, services make use of handlers. Handlers, however, can be freely used in other contexts as well.

Handlers are [storable objects](/foundations-module/utilities/stores.md) that also implement a `get_type` method. For example, handlers for the [logging service](/foundations-module/utilities/handlers-and-services/logging-service.md) are of the *logging* type.

Services are meant to be central hubs (i.e., singleton instances) for performing certain actions. It's not mandatory, but we designed all of our services to delegate the responsibility of performing the actions to a handler. For example, a service inheriting the [`AbstractHandlerService`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Services/AbstractHandlerService.php) class always performs the actions with the same handler whereas a service inheriting the [`AbstractMultiHandlerService`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Services/AbstractMultiHandlerService.php) class needs to be instructed which registered handler to use.

{% hint style="info" %}
Handlers are not meant to be used directly. An object usually has one-or-more registered handlers that it can perform actions with. That's why the [`HandlerAwareInterface`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/HandlerAwareInterface.php) (and the corresponding [trait](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/HandlerAwareTrait.php)) and the [`MultiHandlerAwareInterface`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/MultiHandlerAwareInterface.php)  (and the corresponding [trait](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/MultiHandlerAwareTrait.php)) are very important.
{% endhint %}

The handlers are also prime candidates for [extension action traits](/foundations-module/actions/extension-action-traits.md). There are 3 traits that the foundations module comes with:

* [`OutputHandlersTrait`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/Actions/OutputHandlersTrait.php) -- using objects will call the `output` method of their registered handlers.
* [`RunHandlersTrait`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/Actions/RunHandlersTrait.php) -- using objects will call the `run` method of their registered handlers
* [`ResetHandlersTrait`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Handlers/Actions/ResetHandlersTrait.php) -- using objects will call the `reset` method of their registered handlers.

For example, a [multi-handler-aware-service](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Utilities/Services/AbstractMultiHandlerService.php) implementing the [`OutputtableInterface`](https://github.com/deep-web-solutions/wordpress-framework-foundations/blob/master/src/includes/Actions/OutputtableInterface.php) and using the `OutputHandlersTrait` mentioned above will automagically call the `output` method of all its registered handlers also implementing the `OutputtableInterface` when the service's own `output` method is called. Pretty neat, huh?


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://framework.deep-web-solutions.com/foundations-module/utilities/handlers-and-services.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
