Add failing test case for constructor + readonly + list + constructor_arguments
It's an intended behavior, see https://automapper.jolicode.com/latest/getting-started/configuration/ on constructStrategy
Adding
#[Mapper(constructorStrategy: ConstructorStrategy::ALWAYS)]
on top of class make the test work
By default, if all properties from the source are not present on the target constructor we build the class without invoking the constructor
Otherwise we generate it, this parameter force the generation of the constructor.
Maybe we could always generate it and use this behavior depending on a context value instead ?
By default, if all properties from the source are not present on the target constructor we build the class without invoking the constructor
I think this could confusion with the parameter constructor_arguments. I was expecting to seed some parameters the automapper could not find in the source.
That's being said, I understand what you explained. I do think this should be clarified in the documentation.
Maybe we could always generate it and use this behavior depending on a context value instead ?
I was thinking that indeed. But actually, automapper will never be able to construct my target based on the source. So I'll always need to repeat the context option. So now, I don't think it's useful anymore.
TL;DR: It may be only a doc issue.
I was thinking that indeed. But actually, automapper will never be able to construct my target based on the source. So I'll always need to repeat the context option. So now, I don't think it's useful anymore.
Basically we would generate both possibility of construction and if constructor arguments is present for this class we use the constructor (otherwise we don't)
Think it will work better.
The constructor strategy would still be present and would determine what's the default behavior when constructor arguments are not present in the context :
- Never : will always use cached reflection (wether there is constructor arguments or not)
- Auto :
- If constructor can be done with source properties : use it
- If constructor can not be done with source properties and constructor arguments present : use it
- If constructor can not be done with source properties and constructor arguments not present : do not use it
- Always : always use constructor wether there is constructor arguments or not
It's up to you, but what is sure is I don't need this feature
It's up to you, but what is sure is I don't need this feature
Could be useful if there is code that can give those constructor arguments and other that cannot for the same mapping
I'm closing this, don't have the time to do that and even if the feature can be useful, i never needed it.