2
這是我的服務提供商:Laravel:爲什麼在實例化其提供的類時未註冊註冊的服務提供者?
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
class ESServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('\Elastica\Search', function ($app) {
$client = new \Elastica\Client(array(
'host' => env('ES_HOST'),
'port' => env('ES_PORT')));
$search = new \Elastica\Search($client);
$search->addIndex(Config::get('constants.es_index'))->addType(Config::get('constants.es_type'));
return $search;
});
}
}
當(使用var_dump()
/dd()
驗證)注入的\Elastica\Search\
關閉(第2參數去singleton()
)不會被調用的情況。提供者已正確註冊 - 按上述進行驗證。爲什麼?