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

Provider with existing service id not found. #209

Open
subiabre opened this issue Nov 28, 2024 · 0 comments
Open

Provider with existing service id not found. #209

subiabre opened this issue Nov 28, 2024 · 0 comments

Comments

@subiabre
Copy link

Providers are not being correctly registered using the Symfony Bundle version of the AutoMapper under release 9.2 in Symfony 6.

Implementing the following mapper:

# src/Mapping/UserMapProvider.php
namespace App\Mapping;

use AutoMapper\Provider\ProviderInterface;

class UserMapProvider implements ProviderInterface
{
    public function provide(string $targetType, mixed $source, array $context): object|array|null
    {
        var_dump($targetType, $source, $context);
        exit;
    }
}
# src/Entity/User.php
namespace App\Entity;

use App\Mapping\UserMapProvider;
use AutoMapper\Attribute\MapProvider;

#[MapProvider(provider: UserMapProvider::class)]
class User

Throws the exception Provider with id "App\\Mapping\\UserMapProvider" not found.. Manually supplying the provider to Automapper::create() works successfully, but when using the AutoMapperInterface from Symfony's dependency injection fails even when registering the map provider as a public service.

The documentation states that "When using the Symfony Bundle version of the AutoMapper, the provider will be the service id, which may be different from the class name" but the service id is correct:

$ bin/console debug:container App\\Mapping\\UserMapProvider

Information for Service "App\Mapping\UserMapProvider"
=====================================================

 ---------------- ----------------------------- 
  Option           Value                        
 ---------------- ----------------------------- 
  Service ID       App\Mapping\UserMapProvider  
  Class            App\Mapping\UserMapProvider  
@subiabre subiabre changed the title Provider with id existing service id not found. Provider with existing service id not found. Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant