Domain Service
Description
Encapsulates domain logic that doesn't naturally fit within an Entity or Value Object. Often orchestrates operations across multiple domain objects.
Definition Schema
The definition for a domain_service
component expects the following structure:
{
"$defs": {
"ServiceDependencyInputDTO": {
"description": "Defines a dependency to be injected into the Service's __init__.",
"example": {
"assigned_attribute_name": "_emailer",
"param_name": "email_service",
"param_type_str": "EmailService"
},
"example_with_explicit_import": {
"param_import_from_module": "sqlalchemy.ext.asyncio",
"param_import_names": [
"AsyncSession"
],
"param_name": "async_session_factory",
"param_type_str": "AsyncSession"
},
"properties": {
"param_name": {
"description": "Name of the parameter in __init__ (e.g., 'user_repository')",
"title": "Param Name",
"type": "string"
},
"param_type_str": {
"description": "Type hint string for the parameter (e.g., 'UserRepository')",
"title": "Param Type Str",
"type": "string"
},
"assigned_attribute_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Name of the attribute to assign the dependency to on self (e.g., '_repo'). Defaults to '_' + param_name if None.",
"title": "Assigned Attribute Name"
},
"param_import_from_module": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Optional: Explicit module to import the dependency type from (e.g., 'sqlalchemy.ext.asyncio').",
"title": "Param Import From Module"
},
"param_import_names": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"description": "Optional: Explicit list of names to import from the module (e.g., ['AsyncSession']). Used if param_import_from_module is set.",
"title": "Param Import Names"
}
},
"required": [
"param_name",
"param_type_str"
],
"title": "ServiceDependencyInputDTO",
"type": "object"
}
},
"description": "DTO for defining a Domain Service class within a Bounded Context.",
"example": {
"bounded_context_name": "ordering",
"dependencies": [],
"name": "OrderProcessingService"
},
"properties": {
"name": {
"description": "Name of the service class (e.g., 'UserManagementService')",
"title": "Name",
"type": "string"
},
"dependencies": {
"description": "List of dependencies for the __init__ method.",
"items": {
"$ref": "#/$defs/ServiceDependencyInputDTO"
},
"title": "Dependencies",
"type": "array"
},
"bounded_context_name": {
"description": "Name of the Bounded Context",
"title": "Bounded Context Name",
"type": "string"
}
},
"required": [
"name",
"bounded_context_name"
],
"title": "DomainServiceInputDTO",
"type": "object"
}
Naming and Location Conventions
Class: PascalCase, typically ends with 'Service'. File: ${domain_service_name}.py
(based on ${domain_service_name}
). Location: app/domain/${bounded_ctx}/services
. (Requires context: ['bounded_ctx'])
Example Definition
{
"name": "OrderProcessingService",
"bounded_context_name": "ordering",
"dependencies": []
}