3

When I decorate my domain class with [AdaptTo("[name]Dto"), GenerateMapper] everything works fine, but when I use:

    public class MappingRegister : ICodeGenerationRegister
    {
        public void Register(CodeGenerationConfig config)
        {
            config.AdaptTo("[name]Read")
                .ForType<Command>();

            config.GenerateMapper("[name]Mapper")
                .ForType<Command>();
        }
    }

it generates the same dto class as with an attribute, but the mapper class is empty:

    public static partial class CommandMapper
    {
    }

What do I miss?

Update

So the issue that I have is not with attribute vs ICodeGenerationRegister implementation, but the fact that I have to run the build twice. The First time it generates an empty mapper class and on the second build, I get the extension methods generated.

Here is my project config

...
  <Target Name="Mapster" AfterTargets="AfterBuild">
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n Commands.Dtos -o Dtos" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n Commands.Dtos -o Dtos" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n Commands.Dtos -o Dtos" />
  </Target>
...

Mapster tool version 8.0.1

Nafas
  • 183
  • 1
  • 9

0 Answers0