Build a service
Use services for external integrations, shared infrastructure, and orchestration that spans models. Keep entity-specific rules in models.
Define and configure a service
Start with My First Service, then use the service reference for the base class, configuration parameters, registration, and dependency injection. Let the framework resolve dependencies and manage service instances.
Manage startup and shutdown
Follow the service lifecycle when resolving dependencies, initializing resources, and closing them. Make resource cleanup part of the implementation rather than leaving it to process termination.
Coordinate and observe work
Use events when components need to react to changes, logging to explain runtime behavior, and typed errors to report failures consistently.
Expose and test behavior
Expose service operations through the appropriate interface, or provide local CLI commands for administrative work. Use the application test harness to exercise services with explicit test configuration and controlled dependencies.