Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI-like PHP Attributes (Autowiring feature) #130

Closed
mrVrAlex opened this issue Apr 26, 2022 · 3 comments
Closed

DI-like PHP Attributes (Autowiring feature) #130

mrVrAlex opened this issue Apr 26, 2022 · 3 comments
Labels

Comments

@mrVrAlex
Copy link

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

Hi!
We have MVP solution for autowiring (auto-generate PHP configs for service-manager): https://github.com/opsway/laminas-service-manager-attributes

It is looks like:

#[DI\Factory(InvokableFactory::class)]
#[DI\AliasTo(Example6Service::class)]
class Example1Service implements Example6Service
{
}

or even

#[DI\AutoWireFactory]
class Example4Service
{
    public function __construct(
        #[DI\InjectService(Example2Service::class)] private $example3,
        private Example7ServiceInterface $example7
    ) {
    }
}

It is solution help us decrease a lot human mistakes and misconfiguration between code and configuration for dependencies.

So my question:
Should we continue develop & maintain this package as separate solution? Or we can make separate package as part of laminas vendor packages? Or even make this solution as part of core service-manager package?
What you think about it?)

@Ocramius
Copy link
Member

I'm personally not a fan of having DI happen via annotations, as it wires implementation with container definition, defeating its original purpose.

Still, did you see bitexpert/disco? Should be close to your work...

@froschdesign
Copy link
Member

@shandyDev
Check also https://github.com/reinfi/zf-dependency-injection

@boesing
Copy link
Member

boesing commented Mar 5, 2023

I do not like this kind of magic as well, mostly due to the way that it is some magic hidden in the application rather than having a proper configuration. Another problem is, that there can be multiple services aliasing the same interface which is not properly addressable with these annotations. If there is a config, almost every IDE will already show you if an array key is declared twice in the same array.

But I am actually trying to provide an AOT factory which is based on ReflectionBasedAbstractFactory: #180

This will still require upstream projects to have a minimum configuration (i.e. manual alias mapping and manual factory mapping - to ReflectionBasedAbstractFactory).

However, since there are already 3rd-party libraries out there which does provide this feature, I'd say we are not gonna work more on this than necessary.

@boesing boesing closed this as completed Mar 5, 2023
@boesing boesing added Feature Request Won't Fix This will not be worked on labels Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants