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

Skip to content

[DI] Cannot decorate lazy, final class using interface proxying #49333

@kbond

Description

@kbond

Symfony version(s) affected

6.2.0

Description

When trying, you get the following exception:

  1. Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Cannot generate lazy proxy for service "App\Wrapper.inner".
  2. Symfony\Component\VarExporter\Exception\LogicException: Cannot generate lazy proxy: class "App\Implementation" is final.

How to reproduce

Reproducer: https://github.com/kbond/symfony-reproducer/tree/decorated-lazy-service

interface Contract
{
}

#[Autoconfigure(lazy: Contract::class)]
final class Implementation implements Contract
{
}

#[AsDecorator(decorates: Implementation::class)]
final class Wrapper implements Contract
{
    public function __construct(private Contract $inner)
    {
    }
}

Then inject Implementation somewhere.

Possible Solution

Removing final from the decorated class (Implementation above) solves the issue but this is not ideal.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions