乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      .net5 使用AutoMapper

       實(shí)力決定地位 2021-04-01

      步驟1:項(xiàng)目引用

      AutoMapper

      AutoMapper.Extensions.Microsoft.DependencyInjection

      步驟2:建立文件 DevProCommonFile

      IProfile:是一個空接口,主要用來動態(tài)加載文件時查找相關(guān)文件,也就時說DevProCommonFile這種文件可以建立多個,只要繼承
      Profile, IProfile就會被框架加入
      using AutoMapper;using Dev.WooNet.Model.DevDTO;using Dev.WooNet.Model.Models;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Dev.WooNet.AutoMapper.ProFiles
      {    /// <summary>
          /// 公共映射文件    /// </summary>
          public class DevProCommonFile : Profile, IProfile
          {        public DevProCommonFile()
              {
                  CreateMap<DepartData, DevDepartment>();          //.ForMember(a => a.ContId, opt => opt.Ignore())          //.ForMember(a => a.CreateUserId, opt => opt.Ignore())          //.ForMember(a => a.CreateDateTime, opt => opt.Ignore())          //.ForMember(a => a.ModifyUserId, opt => opt.Ignore())          //.ForMember(a => a.ModifyDateTime, opt => opt.Ignore());        }
             
          }
      }

      步驟3:設(shè)置加載文件規(guī)則

      建立Mappings 定一個擴(kuò)展方法AddDevMapperFiles

      using AutoMapper;using Microsoft.Extensions.DependencyInjection;using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;namespace Dev.WooNet.AutoMapper.Extend
      {   public static class Mappings
          {      
      
              /// <summary>
              ///映射文件        /// </summary>
              /// <param name="service"></param>
              public static void AddDevMapperFiles(this IServiceCollection service)
              {            var allType =
                Assembly
                   .GetEntryAssembly()//獲取默認(rèn)程序集
                   .GetReferencedAssemblies()//獲取所有引用程序集             .Select(Assembly.Load)
                   .SelectMany(y => y.DefinedTypes)
                   .Where(type => typeof(IProfile).GetTypeInfo().IsAssignableFrom(type.AsType()));
                  service.AddAutoMapper(allType.ToArray());
      
                  
      
              }
          }
      }

      步驟4:Startup 的ConfigureServices進(jìn)行注冊

      services.AddDevMapperFiles();(上面擴(kuò)展方法)

      步驟5:應(yīng)用 在控制器注入 IMapper 

      private IMapper _IMapper { get; set; }

      然后 var deptinfo = _IMapper.Map<DevDepartment>(departData);

      這樣就完成了AutoMapper使用

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多