Support the ongoing development of Laravel.io →
posted 10 years ago
IOC

I'm trying to do automatic resolution of dependencies.

I've got this code in my routes.php file:

App::singleton('Client', function($app)
{
    $client = App::make('ClientInterface');
    $client = $client->getCurrent();
    return $client;
});
App::singleton('AlerterInterface', function($app)
{
    $replacers = array( new ItemReplacer );
    $messager = new SessionAlerter($prefix='alerter_machine', $replacers);
    return $messager;
});

Then, I've got this in a controller:

public function __construct( Shop\Product $product, AlerterInterface $alerter, Client $client )

Oddly, the AlerterInterface resolves, but the Client does not. and I get this error:

ReflectionException
Class Client does not exist

I can load the client just fine if I take it out of __construct's parameters and put it into the method, like this:

    $this->client = App::make('Client');

Any idea what's going on?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ipsod ipsod Joined 24 Sep 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.

© 2025 Laravel.io - All rights reserved.