### **Booting Providers** ###
After all providers have been registered, they are "booted". This will fire the ``boot`` method on each provider. A common mistake when using service providers is attempting to use the services provided by another provider in the ``register`` method. Since, within the ``register`` method, we have no gurantee all other providers have been loaded, the service you are trying to use may not be available yet. So, service provider code that uses other services should always live in the ``boot`` method. The ``register`` method should **only** be used for, you guessed it, registering services with the container.
Within the ``boot`` method, you may do whatever you like: register event listeners, include a route file, register filters, or anything else you can imagine. Again, use the provider as organizational tools. Perhaps you wish to group some related event listeners together? Placing them in the ``boot`` method of a service provider would be a great approach! Or, you could include an "events" or "routes" PHP file:
~~~
<!--lang:php-->
public function boot()
{
require_once __DIR__.'/events.php';
require_once __DIR__.'/routes.php';
}
~~~
Now that we've learned about dependency injection and a way to organize our projects around providers, we have a great foundation for building well-architected Laravel applications that are maintainable and testable. Next, we'll explore how Laravel itself uses providers, and how the framework works under the hood!
> ### **Don't Box Yourself In** ###
>
> Remember, don't assume that service providers are something that only packages use. Create your own to help organize your application's services.
>
- Dependency Injection
- The Problem
- Build A Contract
- Take It further
- Too Much Java?
- The IoC Container
- Basic Binding
- Reflective Resolution
- Interface As Contract
- Strong Typing & Water Fowl
- A Contract Example
- Interface & Team Development
- Service Provider
- As Bootstrapper
- As Organizer
- Booting Providers
- Providing The Core
- Application Structure
- MVC Is Killing You
- Bye, Bye Models
- It's All About The Layers
- Where To Put "Stuff"
- Applied Architecture: Decoupling Handles
- Decoupling Handlers
- Other Handlers
- Extending The Framework
- Manager & Factories
- Cache
- Session
- Authentication
- IoC Based Extension
- Request Extension
- Single Responsibility Principle
- Open Closed Principle