Dependency Injection only happens when using the IoC/Service container to resolve a class or call a method. If you are calling a method yourself and it has required arguments, you have to pass those arguments. Laravel does not change how PHP works.
None of these will ever involve dependency injection as they are direct method calls on an object and do not use the container:
$this->anything(); // just a method call
$something->anything(); // just another method call
The reason you will get constructor dependencies injected is because those particular classes are resolved using the IoC container. Usually the framework is the caller of such code, not you directly. When the framework calls a method on a class, it may use the container to make that call, which is where Method Injection comes into play.
The container has a call method with comment:
"Call the given Closure / class@method and inject its dependencies."
The boot method of Service Providers is called via the IoC container and that method will have dependencies injected as per the Laravel Documentation on Service Providers.
"You are able to type-hint dependencies for your service provider's boot method. The service container will automatically inject any dependencies you need..."
Laravel 5.2 Docs - Service Providers - The Boot method
From Illuminate\Foundation\Application@bootProvider:
protected function bootProvider(ServiceProvider $provider)
{
if (method_exists($provider, 'boot')) {
return $this->call([$provider, 'boot']);
}
}
The Application uses the call method to call the boot method on a provider, which is why you can type-hint parameters for the boot method and get Method Injection. It does not directly call boot on the provider object, it uses the container to call it.
To use features of the container, the container has to be used.
-- This is referencing Laravel 5.2, but the IoC is very much the same through the versions.
setSettings()method?Boot()within the same ServiceProvider