久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    .net5 使用AutoMapper

     實力決定地位 2021-04-01

    步驟1:項目引用

    AutoMapper

    AutoMapper.Extensions.Microsoft.DependencyInjection

    步驟2:建立文件 DevProCommonFile

    IProfile:是一個空接口,主要用來動態加載文件時查找相關文件,也就時說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:設置加載文件規則

    建立Mappings 定一個擴展方法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()//獲取默認程序集
                 .GetReferencedAssemblies()//獲取所有引用程序集             .Select(Assembly.Load)
                 .SelectMany(y => y.DefinedTypes)
                 .Where(type => typeof(IProfile).GetTypeInfo().IsAssignableFrom(type.AsType()));
                service.AddAutoMapper(allType.ToArray());
    
                
    
            }
        }
    }

    步驟4:Startup 的ConfigureServices進行注冊

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

    步驟5:應用 在控制器注入 IMapper 

    private IMapper _IMapper { get; set; }

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

    這樣就完成了AutoMapper使用

      本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發現有害或侵權內容,請點擊一鍵舉報。
      轉藏 分享 獻花(0

      0條評論

      發表

      請遵守用戶 評論公約

      主站蜘蛛池模板: 中文字幕亚洲人妻系列| 激情五月开心婷婷深爱| 免费看欧美全黄成人片| 日韩精品卡2卡3卡4卡5| 久爱www人成免费网站| 人妻系列无码专区免费| 日日躁夜夜躁狠狠躁超碰97| 青青国产揄拍视频| 色老头在线一区二区三区| 国产AV影片麻豆精品传媒| 色婷婷久久综合中文久久一本| 日本道精品一区二区三区| 又粗又紧又湿又爽的视频| 午夜毛片不卡免费观看视频| 67194熟妇在线直接进入| 色窝窝免费播放视频在线| 国产丝袜在线精品丝袜不卡| 强奷漂亮人妻系列老师| 粗大挺进朋友人妻淑娟| 亚洲综合成人av在线| 奇米影视7777狠狠狠狠色| 一卡二卡三卡四卡视频区| AV色欲无码人妻中文字幕| 又色又污又爽又黄的网站| 在线日韩日本国产亚洲| 夜夜高潮夜夜爽高清完整版1| 国产99青青成人A在线| 久久人人爽人人人人片AV| 国精品午夜福利视频不卡| 国产一区二区日韩在线| 精品无码国产一区二区三区51安 | 国产成人亚洲欧美二区综合| 日本中文字幕亚洲乱码| 精品偷拍一区二区三区| 国产精品自在线拍国产电影 | 久久综合综合久久综合| 国产中文字幕一区二区| 99国精品午夜福利视频不卡99| 特级毛片A级毛片免费观看网站| 乱码中字在线观看一二区| 亚洲人成小说网站色在线|