framework-x icon indicating copy to clipboard operation
framework-x copied to clipboard

Allow auto-wiring container-parameters without using factory-callback

Open jkrzefski opened this issue 3 years ago • 2 comments

Imagine you wanted to have a service with a constructor parameter of a string like this:

class UserController
{
    public function __construct(string $hostname)
    {
        // ...
    }
}

Prior to this change, you would have to do this.

$container = new FrameworkX\Container([
    UserController::class => function (string $hostname): UserController {
        return new UserController($hostname);
    },
    'hostname' => 'Some string value',
]);

After this change, you can do this:

$container = new FrameworkX\Container([
    'hostname' => 'Some string value',
]);

I am still relatively new to this framework, so I don't know whether this will break some anything.

jkrzefski avatar Sep 02 '22 16:09 jkrzefski

Hey @jkrzefski, thanks for bringing this up :+1:

This is something we also thought about when implementing the support for variables in container configuration for factory functions (#178, #179, #180, #182, #183, #184), we actually took the more difficult route on purpose. What you're suggesting is definitely a much easier way, but we are unsure what the consequences are if we start supporting this (name collisions, unwanted behavior, etc.).

It might be worth opening a discussion on this topic first and see what needs to be worked out before this new feature can be deployed. What do you think about this?

SimonFrings avatar Sep 05 '22 12:09 SimonFrings

@SimonFrings That you for your feedback. (And sorry for my late response 😥)

I opened a discussion about this topic. https://github.com/clue/framework-x/discussions/192

jkrzefski avatar Oct 03 '22 13:10 jkrzefski

@jkrzefski I think we can close this ticket here for now as we have the ongoing discussion in #192. Let's revisit this once we figured out the consequences and have an idea what different approaches can look like :+1:

SimonFrings avatar Mar 05 '24 08:03 SimonFrings