forrest
forrest copied to clipboard
Request: Support Facadeless Usage
The service can't be injected into methods, because of how it's being registered. Please could we get it to so that the following behaviour is supported (because facades are evil):
function __construct(ForrestService $forrest) {
$this->salesForceService = $forrest;
}
Thanks!
A work-around to this is to write your own class that resolves the service based on the service key
<?php
declare(strict_types=1);
namespace App\Services\Forrest;
use Illuminate\Contracts\Container\Container;
use Omniphx\Forrest\Client as ForrestClient;
class ForrestResolver
{
private const SERVICE_NAME = 'forrest';
public function __construct(private Container $container)
{
}
public function resolve(): ForrestClient
{
return $this->container->make(self::SERVICE_NAME);
}
}
you can then inject and use it like
public function __construct(private ForrestResolver $forrestResolver) {}
...
$this->forrestResolver->resolve()->authenticate();