typerocket icon indicating copy to clipboard operation
typerocket copied to clipboard

Fetching a Service from Container - Backslash mismatch

Open 14nd90 opened this issue 1 year ago • 1 comments

In my config/app.php I was registering a service as per the docs

 'services' => [
    ...
    '\App\Services\UserService',
],

But when it came to getting the service, it was returning NULL $this->user_service = tr_container(\App\Services\UserService::class);

This seems to be because when registering the service, the string provided in config is used as they key in the list, whereas when resolving, the ::class keyword returns the class path without the preceding backslash. Everything works as expected when defining the service without the preceding backslash in config. But I would expect the docs to highlight this, or for there to be a some consistency in key names when registering services.

14nd90 avatar Oct 24 '24 15:10 14nd90

@14nd90

I'll see what we can do.

kevindees avatar Dec 12 '24 16:12 kevindees