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

I usually use facade, however you can alway use

App::make()
Last updated 2 years ago.
0

So using App::make() in another route or model you would use?

$lot = App::make('Acme\Repositories\Lot\LotRepositoryInterface');

I just started reading that Facades weren't ideal for testing so I was trying to avoid them!

Last updated 2 years ago.
0

leoden said:

So using App::make() in another route or model you would use?

$lot = App::make('Acme\Repositories\Lot\LotRepositoryInterface');

If a class is instantiated by the IoC container the interface can just be injected. If using a route closure you'll have to use the App::make() but in another class just inject the interface like you would in a controller.

leoden said:

I just started reading that Facades weren't ideal for testing so I was trying to avoid them!

Facades are no worse for testing than using a closure directly in the route, its best to stick to controllers. Any facade can be partially mocked with Mockery by calling FacadeName::respondsTo('something')... but its not as nice as injecting all dependencies. Injecting all controller dependencies can get very cumbersome though.

Last updated 2 years ago.
0

Thanks for the answers guys much appreciated!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

leoden leoden Joined 13 Mar 2014

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.