Support the ongoing development of Laravel.io →
posted 9 years ago
IOC
Last updated 2 years ago.
0

Hello lucabernardino,

you use dependency injection not because you need to have access to you class but to make your code better organized. usually you bind you class to an interface.

app::bind('MyNamespace/PaymentInterface', function(){ return new PaypalPayment(); })

so in the future is you change a payment method the only change you have to do is this line of code.

a better and more extended explanation can be found on Taylor's book "Laravel: From Apprentice To Artisan"

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.