Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@kbond

Description

@kbond
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.