Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

DotDev.co:
Understanding the Laravel Service Container
Sep 13, 2016 @ 17:56:04

The Dotdev.co blog has posted a tutorial for the Laravel users out there with the goal of helping you understand the Laravel service container, a key part of the framework's functionality and an extensible feature you can adapt to some of your own needs.

Learning how to build an application with Laravel is not just about learning to use the different classes and components within the framework, it is not about remembering all artisan commands or remembering all helper functions (we have Google for that). Learning to code with Laravel is learning the philosophy of Laravel, its elegance and its beautiful syntax. I personally feel it is an art and a craft (its not a coincidence that Laravel developers are sometimes referred to as Web artisans). This is true for any other framework as well.

A major part of Laravel’s philosophy is the Service Container or IoC container. As a Laravel developer, understanding and using the Service Container properly is a crucial part in mastering your craft, as it is the core of any Laravel application.

The post starts with some of the basics about the container and how objects/instances are bound to it. They give an example of binding a FooService class in the "register" methods of providers. A code example is also included showing how to use the service you previously bound. There's also a description of binding interfaces in the IoC, making it easier for custom classes to resolve interfaces when they're implemented. The post wraps up with a bit covering the resolving of dependencies and the code you'll need to set them up.

tagged: laravel service container introduction tutorial framework bind

Link: https://dotdev.co/understanding-laravel-service-container-bd488ca05280#.9gd6v3t4l


Trending Topics: