亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Getting started · AutoMapper/AutoMapper Wiki

系統(tǒng) 2188 0

Getting started · AutoMapper/AutoMapper Wiki

Getting Started

What is AutoMapper?

AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B. As long as type B follows AutoMapper's established convention, almost zero configuration is needed to map two types.

Why use AutoMapper?

Mapping code is boring. Testing mapping code is even more boring. AutoMapper provides simple configuration of types, as well as simple testing of mappings. The real question may be "why use object-object mapping?" Mapping can occur in many places in an application, but mostly in the boundaries between layers, such as between the UI/Domain layers, or Service/Domain layers. Concerns of one layer often conflict with concerns in another, so object-object mapping leads to segregated models, where concerns for each layer can affect only types in that layer.

How do I use AutoMapper?

First, you need both a source and destination type to work with. The destination type's design can be influenced by the layer in which it lives, but AutoMapper works best as long as the names of the members match up to the source type's members. If you have a source member called "FirstName", this will automatically be mapped to a destination member with the name "FirstName". AutoMapper also supports Flattening , which can get rid of all those pesky null reference exceptions you might encounter along the way.

Once you have your types, and a reference to AutoMapper, you can create a map for the two types.

              
                Mapper.CreateMap<Order, OrderDto>();

              
            

The type on the left is the source type, and the type on the right is the destination type. To perform a mapping, use the Map method.

              
                OrderDto dto = Mapper.Map<Order, OrderDto>(order);

              
            

AutoMapper also has non-generic versions of these methods, for those cases where you might not know the type at compile time.

Where do I configure AutoMapper?

If you're using the static Mapper method, configuration should only happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.asax file for ASP.NET applications. Typically, the configuration bootstrapper class is in its own class, and this bootstrapper class is called from the startup method.

How do I test my mappings?

To test your mappings, you need to create a test that does two things:

  • Call your bootstrapper class to create all the mappings
  • Call Mapper.AssertConfigurationIsValid

Here's an example:

              
                AutoMapperConfiguration.Configure();

Mapper.AssertConfigurationIsValid();

              
            

Can I see a demo?

Check out the dnrTV episode on AutoMapper .

Getting started · AutoMapper/AutoMapper Wiki


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 波多野结衣国产一区二区三区 | 亚洲国产精品综合一区在线 | 午夜久久久久久 | 久热中文字幕在线精品免费 | 成年女人色毛片免费 | 妖精视频在线观看网站 | 亚洲狠狠成人综合网 | 国产小视频在线观看 | 国产第二区 | 男女交黄 | 免费色视频网站 | 成人精品一区二区三区中文字幕 | 四虎精品成人免费视频 | 天天摸天天碰色综合网 | 欧美日本一区二区 | 免费观看美女光子让男人玩 | 一级特黄性色生活片一区二区 | 性猛交毛片 | 久久天天躁狠狠躁夜夜2020一 | 日韩欧美在 | 亚洲在线视频播放 | 九月丁香婷婷亚洲综合色 | 日韩成人高清 | 久久久久久岛国免费网站 | 久久精品国产一区二区三区日韩 | 在线观看香蕉免费啪在线观看 | 九九热免费观看 | 久久综合九色综合狠狠97 | 国产精品亚洲综合一区在线观看 | 欧美日韩一区二区三 | 欧美色老太婆 | 国产成人精品曰本亚洲78 | 337p日本欧洲亚洲大胆艺术 | 亚洲欧美日韩中文在线 | 亚洲在线视频观看 | 欧美亚洲国产激情一区二区 | jizz中国人 | 一级特级aaaa毛片免费观看 | 日本不卡高清免费v日本 | 精品亚洲国产国拍 | 亚洲视频免费在线观看 |