종속성 주입을 사용하여 클래스를 생성하려고합니다. 이 클래스는이 서비스 제공IOC contatiner laravel을 사용하여 클래스를 인스턴스화 할 수 없습니다.
class SomethingServiceProvider extends ServiceProvider
{
public function boot()
{
}
public function register()
{
$this->app->singleton('Something', function() {
return new Something('test');
});
}
}
내가 컨트롤러에서이 클래스의 인스턴스를 사용하려고 할 때 ... app.php
class Something
{
private $variable;
public function __construct(string $variable)
{
$this->variable = $variable;
}
}
에 등록 된 자신의 서비스 제공을 가지고
class TestController extends AppBaseController
{
public function __construct(Something $something)
{
$this->something = $something;
}
...
오류가 발생했습니다.
"Unresolvable dependency resolving [Parameter #0 [ string $variable ]] in class Something at Container->unresolvablePrimitive(object(ReflectionParameter)) in Container.php (line 848) "
내가 여기에 실종 된지 확실하지 않습니다. 서비스 공급자에는 생성자가 없습니다. – apokryfos