Where should I put automapper code?

后端 未结 2 500
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 04:16

I\'m using Automapper in Asp.net mvc application. I have a question regard to the usage of automapper

from lots of sample code, I saw people use mapper Mapper.

2条回答
  •  囚心锁ツ
    2020-12-17 05:02

    if you have service layer in your application, it's better to place the automapper in service layer. in any case try to use extension method for mapping your object by automapper like this:

    public static class Mapping
    {
    public static BankflowData CreateBankflowAdjustments(this BankflowData addedBankFlow)
          {
             var bankflow = Mapper.Map(addedBankFlow);
             var newBankflow = Underlying.CreateBankFlowAdjustments(bankflow);
             return Mapper.Map(newBankflow);
          }
    }
    

    it will make your code more readable and will separate your concerns. take this for more info

提交回复
热议问题