- Composer
composer require zhwei/laravel-autowire
- Register Service Provider (Lumen only)
$app->register(\Zhwei\LaravelAutowire\AutowireServiceProvider::class);
- Autowire
Any class implemented the Zhwei\LaravelAutowire\AutowireAble
interface will trigger auto-wire after container resolution.
class HelloController implements Zhwei\LaravelAutowire\AutowireAble
{
/**
* @autowire
* @var \Illuminate\Contracts\Cache\Factory
*/
protected $cache;
public function hello()
{
return $this->cache->store()->get('hello');
}
}
or trigger by your self:
$hello = new HelloController();
Zhwei\LaravelAutowire\AutowireInjector::inject(app(), $hello);