Skip to content

Fetching a Service from Container - Backslash mismatch #265

Description

@14nd90

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions