DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Sanjarbek Sobirjonov
Sanjarbek Sobirjonov

Posted on

Service container in Laravel

I'm confused about dependency injection. In the prior time, I haven't faced to dependency injection, to be honest, I haven't used it. What is it? Please, explain for me in simply words.

With regards,
Sanjarbek

Top comments (2)

Collapse
 
hakobyansen profile image
Senik Hakobyan

In simple words: whenever you define a parameter in your class constructor - you define a dependency for that class, so that it can't be initialized without injecting (passing) dependencies that you have required in your constructor.

Laravel does it for you automatically unless you are not injecting abstractions, like interfaces. In those cases you can implement bindings in Service Providers.

Good luck! :)

Collapse
 
sobirjonovs profile image
Sanjarbek Sobirjonov Author

Thank you!!! Got it!

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›