Skip to content

Inability to use dependency injection in the server class #37

Closed
@X-Coder264

Description

@X-Coder264

The server class is currently constructed in \LaravelJsonApi\Core\Server\ServerRepository like this:

$server = new $class($this->container, $name);

I like to always use DI instead of facades and global helpers but that is not possible at the moment because of this line (for example when adding a scope that needs some dependency in the serving method of the server).
My suggestion would be to have the server bound in the container under a convention key, like jsonapi_server_{$name}.

So the line from above would become

$server = $this->container->make("jsonapi_server_{$name}");

That way we could completely override the binding in our code (or just contextually bind a dependency, like a guard for example if needed).

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions