Domain services in HexCore handle business operations that span multiple entities or require coordination that does not naturally belong to a single entity.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt
Use this file to discover all available pages before exploring further.
BaseDomainService is the base class for all domain services. Beyond providing access to the configured EventBus, it ships with a powerful list_entities() method that handles filtering, sorting, pagination, and full-text search out of the box — driven by a declarative QueryRequestDTO. This page documents the class, all query DTOs, and shows a complete service example.
BaseDomainService
BaseDomainService lives in hexcore.domain.services.
Constructor
The active
EventBus instance. Defaults to the bus configured in ServerConfig. Override this in tests or specialised setups by passing a custom EventBus directly.self.config = LazyConfig.get_config() so subclasses have access to all project settings without an extra import.
list_entities()
list_entities is the primary query engine. It inspects the repository for an optional query_all(query) method:
- If
query_allexists on the repository (e.g. a SQLAlchemy implementation that pushes filters to SQL), it is called directly and the results are wrapped in aQueryResponseDTO. - If
query_alldoes not exist,list_entitiescallsrepository.list_all(limit=None, offset=0)to fetch all entities in-memory, then applies search, filtering, sorting, and pagination viaquery_entities().
Query DTOs
QueryRequestDTO
Maximum number of items to return. Must be ≥ 1.
Number of items to skip before collecting results. Must be ≥ 0.
Full-text search string. When set, only entities that contain this string (case-insensitive) in any of the
search_fields are returned. If search_fields is empty, HexCore infers searchable fields automatically from scalar field types (str, int, float, bool, date, datetime).List of entity field names to search within. Leave empty to search all scalar fields.
List of filter conditions applied with
AND logic. All conditions must match for an entity to be included.List of sort conditions applied in priority order. The first condition is the primary sort key (highest precedence); each subsequent condition is a tiebreaker. Multi-key sort is stable.
QueryResponseDTO
The page of entities matching the query.
Total number of entities that match the query (before pagination).
The limit value echoed from the request.
The offset value echoed from the request.
True when there are more items beyond the current page.FilterConditionDTO
Name of the entity attribute to filter on. Must be non-empty.
Comparison operator. See
FilterOperator below.Value to compare the field against. For
IS_NULL, this field is ignored.FilterOperator
| Value | String | Description |
|---|---|---|
EQ | "eq" | Equal to |
NE | "ne" | Not equal to |
GT | "gt" | Greater than |
GTE | "gte" | Greater than or equal |
LT | "lt" | Less than |
LTE | "lte" | Less than or equal |
IN | "in" | Value is in the given list |
NOT_IN | "not_in" | Value is not in the given list |
CONTAINS | "contains" | String field contains the given substring (case-insensitive) |
STARTSWITH | "startswith" | String field starts with the given prefix (case-insensitive) |
ENDSWITH | "endswith" | String field ends with the given suffix (case-insensitive) |
IS_NULL | "is_null" | Field is None |
SortConditionDTO
Name of the entity attribute to sort by. Must be non-empty.
Sort direction:
SortDirection.ASC ("asc") or SortDirection.DESC ("desc").Complete service example
The example below defines aProductService with three real-world methods: list_products (paged query with filters), create_product, and deactivate_product.
Composing queries
BuildQueryRequestDTO programmatically for complex query scenarios: