You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the AutoMapper bundle, if you create a custom MapperConfigurationInterface and call $metadata->getPropertiesMapping(), the mappings will be generated BEFORE the ObjectTransformer was loaded into the system. The problem comes with how the objects are instantiated:
A) When the container creates theJane\Component\AutoMapper\Transformer\ChainTransformerFactory service, in the compiled container, it eventually calls:
This is a minor issue - it can just cause WTF moments. I couldn't figure out why a property was NOT apparently being mapped... but then WOULD be mapped in the end.
How to reproduce
symfony new reproducing_jane_missing_object_transformer
cd reproducing_jane_missing_object_transformer
composer require jane-php/automapper-bundle
Create a mapping config class - throw an exception:
If you look at the stacktrace, you'll see something like:
ContainerTWxKxjp\App_KernelDevDebugContainer->load() at /Users/weaverryan/Sites/os/reproducers/reproducing_jane_missing_object_transformer/var/cache/de_/ContainerTWxKxjp/getChainTransformerFactoryService.php:42
If you look at that line, you'll see it starting the instantiation of the AutoMapperInterface service before the ObjectTransformerFactory is complete, which proves that the custom mapper config class is called before the ObjectTransformerFactory is present.
Possible Solution
One possibility is to inject the AutoMapperInterface dependency into ObjectTransformerFactory lazily in some way so that the chain transformer factory can finish instantiating without triggering the instantiation of the auto mapper.
Cheers!
The text was updated successfully, but these errors were encountered:
Thanks a lot for this detailed issue, sorry I didn't had time to dig into this. I also changed the repository for the AutoMapper component so I'll switch this issue to the new repository.
Jane version(s) affected: 7.5.3
Description
Hi!
In the AutoMapper bundle, if you create a custom
MapperConfigurationInterface
and call$metadata->getPropertiesMapping()
, the mappings will be generated BEFORE theObjectTransformer
was loaded into the system. The problem comes with how the objects are instantiated:A) When the container creates the
Jane\Component\AutoMapper\Transformer\ChainTransformerFactory
service, in the compiled container, it eventually calls:In order to create the
ObjectTransformerFactory
, it needs to load theAutoMapperInterface
service so it can be passed to it.B) But, when the
AutoMapperInterface
is being created, in the cached container, it will call:(where
UserToUserApiMapperConfiguration
is the custom mapper configuration class).C) The
AutoMapper::addMapperConfiguration()
method - https://github.com/janephp/janephp/blob/next/src/Bundle/AutoMapperBundle/AutoMapper.php#L13 - causes theprocess()
method to be called on the custom mapper configuration. However, at this point, theObjectTransformerFactory
hasn't yet finished being added to the system.This is a minor issue - it can just cause WTF moments. I couldn't figure out why a property was NOT apparently being mapped... but then WOULD be mapped in the end.
How to reproduce
Create a mapping config class - throw an exception:
Then, use the AutoMapper somewhere so that it's not removed from the container:
Finally:
If you look at the stacktrace, you'll see something like:
If you look at that line, you'll see it starting the instantiation of the AutoMapperInterface service before the ObjectTransformerFactory is complete, which proves that the custom mapper config class is called before the
ObjectTransformerFactory
is present.Possible Solution
One possibility is to inject the
AutoMapperInterface
dependency intoObjectTransformerFactory
lazily in some way so that the chain transformer factory can finish instantiating without triggering the instantiation of the auto mapper.Cheers!
The text was updated successfully, but these errors were encountered: