Are you looking for a way to resolve things like translation, validation and config from the Laravel IoC? Look no further!
Make yourself a service provider (whether in a common tools package or in your project) and add the following to it in the register method:
What you've done is mapped all the string-registered services to their most abstract but also most specific types. Config is a good example of where you should be binding the class name and not an interface because the only interfaces it implements are ArrayAccess, and that's obviously wrong! :)
Happy constructor-injecting!
Make yourself a service provider (whether in a common tools package or in your project) and add the following to it in the register method:
$this->app->bind('Symfony\Component\Translation\TranslatorInterface', function ($app) { return $app['translator']; }); $this->app->bind('Illuminate\Config\Repository', function ($app) { return $app['config']; });
What you've done is mapped all the string-registered services to their most abstract but also most specific types. Config is a good example of where you should be binding the class name and not an interface because the only interfaces it implements are ArrayAccess, and that's obviously wrong! :)
Happy constructor-injecting!
Comments
Post a Comment