🔴 Laravel
Beginner
What is the Service Container in Laravel?
Answer
The Service Container (IoC Container) is a powerful tool for managing class dependencies and performing dependency injection. When you type-hint a dependency in a controller constructor or method, Laravel's container automatically resolves and injects it. Bind a class: $this->app->bind(UserRepository::class, EloquentUserRepository::class). Singleton (one instance): $this->app->singleton(Cache::class, RedisCache::class). Resolve manually: app(UserRepository::class) or resolve(UserRepository::class). The container uses PHP Reflection to inspect constructor type-hints and automatically resolve nested dependencies. This is the foundation of how Laravel wires up controllers, commands, middleware, and every other component.