Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] allow extending Autowire attribute#49433

Merged
nicolas-grekas merged 1 commit into
symfony:6.3from
kbond:di-extend-autowire
Feb 21, 2023
Merged

[DependencyInjection] allow extending Autowire attribute#49433
nicolas-grekas merged 1 commit into
symfony:6.3from
kbond:di-extend-autowire

Conversation

@kbond

@kbond kbond commented Feb 17, 2023

Copy link
Copy Markdown
Member
Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets n/a
License MIT
Doc PR todo

This allows 3rd party package developers to make custom Autowire attribute helpers. Example:

class Repository extends Autowire
{
    public function __construct(string $class)
    {
        parent::__construct(expression: \sprintf("service('some.repository.factory').create('%s')", $class));
    }
}

And then it could be used with:

/**
 * @param ObjectRepository<User> $repository
 */
public function __construct(#[Repository(User::class)] private ObjectRepository $repository)
{
}

@kbond
kbond requested a review from dunglas as a code owner February 17, 2023 21:18
@carsonbot carsonbot added this to the 6.3 milestone Feb 17, 2023
@carsonbot carsonbot changed the title [DI] allow extending Autowire attribute [DependencyInjection] allow extending Autowire attribute Feb 17, 2023
Comment thread src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php Outdated
@nicolas-grekas

Copy link
Copy Markdown
Member

Thank you @kbond.

@nicolas-grekas
nicolas-grekas merged commit bef46c8 into symfony:6.3 Feb 21, 2023
@kbond
kbond deleted the di-extend-autowire branch February 26, 2023 11:17
@fabpot fabpot mentioned this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants