$30 off During Our Annual Pro Sale. View Details »

The final Laravel Service Container talk (Laracon Online)

The final Laravel Service Container talk (Laracon Online)

Laravel's service container is one of the most challenging aspects of the framework. I know, because I have been there too. It just didn't click with me for a very long time.

It's a little funny because, at its core, the concept and implementation of a service container are relatively simple compared to other parts of the framework. Yeah, Eloquent, I'm talking about you!

We always talk about the concept, theory, and HOW to use the service container, but that's where I see the issue. It's time to include the WHEN and WHY in the discussion.

My humble goal with this talk is to make it the final service container tutorial you will need!

Christoph Rumpel

March 17, 2021
Tweet

More Decks by Christoph Rumpel

Other Decks in Technology

Transcript

  1. Welcome

    View Slide

  2. View Slide

  3. @christophrumpel

    View Slide

  4. The final Laravel
    Service Container talk

    View Slide

  5. THE SERVICE CONTAINER
    Binding
    Making
    Resolving
    Dependency Injection
    Inversion Of Control IOC Container
    Providers
    Singleton
    Auto-Resolving
    Facades
    Interface Binding
    Context Binding
    PSR-11
    !

    View Slide

  6. FORGET ABOUT THE HOW
    LETS FOCUS ON THE WHY
    (AND WHEN)

    View Slide

  7. What if there was no
    Service Container?

    View Slide

  8. Loading Example ...

    View Slide

  9. WHY WE NEED THE
    SERVICE CONTAINER

    View Slide

  10. WHY WE NEED THE
    SERVICE CONTAINER
    Better dependency handling
    Less responsibilities
    No duplicated code
    Change the control flow

    View Slide

  11. WHO IS IN CONTROL

    View Slide

  12. WHO IS IN CONTROL

    View Slide

  13. WHO IS IN CONTROL
    = Inversion Of Control (IOC)

    View Slide

  14. Ok, HOW is important too
    More Examples

    View Slide

  15. Auto-Resolving
    Before
    After

    View Slide

  16. Explicit Binding
    AppServiceProvider

    View Slide

  17. Facades
    Before
    After

    View Slide

  18. Facades
    Before
    After

    View Slide

  19. Facades & Fakes
    Example Time

    View Slide

  20. Extending & Overriding
    Example Time

    View Slide

  21. src/Illuminate/Foundation/Http/Kernel.php
    Bind an instance

    View Slide

  22. Singletons
    AuthServiceProvider

    View Slide

  23. Packages

    View Slide

  24. WHY WE NEED THE
    SERVICE CONTAINER
    Better dependencies handling
    Less responsibilities
    No duplicated code
    Change the control flow

    View Slide

  25. Resources
    The Best Introduction To Laravel's Service Container
    https://bit.ly/3triBqS
    The Service Container, with Christoph Rumpel & Matt Stauffer
    https://bit.ly/3eIcsT8
    4 Ways The Laravel Service Container Helps Us
    Managing Our Dependencies
    https://bit.ly/3eOjCFi
    Mastering The Illuminate Container
    https://bit.ly/38NAAjr
    Service Container Fundamentals
    https://bit.ly/38P1JT4

    View Slide

  26. @christophrumpel
    NO SPEAKERS PROPERTY
    Base Eloquent Model
    Laravel Core
    Adventures
    https://laravelcoreadventures.com

    View Slide

  27. Code Examples
    Git repository with my code examples
    https://bit.ly/3ePkhXg

    View Slide

  28. View Slide

  29. The End

    View Slide