What are Services in CodeIgniter 4?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex CodeIgniter topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Services in CodeIgniter 4 provide a lightweight dependency injection mechanism and a central registry for framework components. The Config\Services class defines factory methods for all framework services. Access a service: $email = service("email") or \Config\Services::email(). Services return either a shared instance (singleton) with service("name", false) or a new instance. Key services: router, request, response, session, email, validation, logger, cache, encryption, pager. You can override any service by creating a Services class in app/Config/ that extends the system one — this is how you swap framework components with custom implementations without touching the core code.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong CodeIgniter candidates.