title: How to create a reusable mapping profile with Mapster?
body: <p>I have a .Net 5 Web Api project and want to use</p>
  <blockquote>
  <p>Mapster v7.2.0</p>
  </blockquote>
  <p>to avoid mapping objects manually. The following code shows a sample scenario</p>
  <ul>
  <li>setup a mapping configuration</li>
  <li>map from multiple sources</li>
  <li>map to fields with different names</li>
  </ul>
  <p>.</p>
  <pre><code>[ApiController]
  [Route(&quot;[controller]&quot;)]
  public class MyController : ControllerBase
  {
      [HttpGet]
      public ActionResult&lt;UsernameWithTodoTitle&gt; Get()
      {
          TypeAdapterConfig&lt;(User, Todo), UsernameWithTodoTitle&gt;
              .NewConfig()
              .Map(dest =&gt; dest, src =&gt; src.Item1) // map everything from user
              .Map(dest =&gt; dest, src =&gt; src.Item2) // map everything from todo
              .Map(dest =&gt; dest.TodoTitle, src =&gt; src.Item2.Title); // map the special fields from todo
          
          var user = new User { Username = &quot;foo&quot;, FieldFromUser = &quot;x&quot; };
          var todo = new Todo { Title = &quot;bar&quot;, FieldFromTodo = &quot;y&quot; };
          
          var usernameWithTodoTitle = (user, todo).Adapt&lt;(User, Todo), UsernameWithTodoTitle&gt;();
          
          return Ok(usernameWithTodoTitle);
      }
  }
  
  public class User
  {
      public string Username { get; set; }
      public string FieldFromUser { get; set; }
  }
  
  public class Todo
  {
      public string Title { get; set; } // !! map this one to the TodoTitle field !!
      public string FieldFromTodo { get; set; }
  }
  
  public class UsernameWithTodoTitle
  {
      public string Username { get; set; }
      public string TodoTitle { get; set; } // !! this one is special, is has a different name !!
      public string FieldFromUser { get; set; }
      public string FieldFromTodo { get; set; }
  }
  </code></pre>
  <p>When running the app the mapping seems to work fine this way</p>
  <p><a href="https://i.stack.imgur.com/Dytl4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dytl4.png" alt="enter image description here" /></a></p>
  <p>I had to setup the configuration this way, other ways didn't work for me. But there are 3 things left to be solved</p>
  <ul>
  <li>The configuration looks wrong to me. It maps everything from the todo and maps the special field again ... so it might loop through multiple times? This might get expensive, if there are multiple fields with different names</li>
  <li>I created the configuration inside the controller. How can I create a reusable mapping profile class registered once globally?</li>
  <li>When having a mapping profile this line <code>var usernameWithTodoTitle = (user, todo).Adapt&lt;(User, Todo), UsernameWithTodoTitle&gt;();</code> looks quite messy to me. Better would be <code>var usernameWithTodoTitle = UsernameWithTodoTitle.Adapt((user, todo)) /* pass in as a tuple */</code> because based on the parameter type it chooses the correct mapping profile</li>
  </ul>
  <p>Do you guys have any ideas how to create such a mapping profile?</p>