zoukankan      html  css  js  c++  java
  • AutoMapper introduction


    http://automapper.org/

    A convention-based object-object mapper映射.

    100% organic and gluten-free.

    Takes out all of the fuss of mapping one object to another.

    convention 大会;[法] 惯例;[计] 约定;[法] 协定;习俗

    https://github.com/AutoMapper/AutoMapper

    What is AutoMapper?

    AutoMapper is a simple little library built to solve a deceptively迷惑地 complex problem - getting rid of code that mapped one object to another.

    This type of code is rather dreary沉闷的,枯燥的 and boring to write, so why not invent a tool to do it for us?

    How do I get started?
    Check out the getting started guide.  

    When you're done there, the wiki goes in to the nitty-gritty details.

    Finally, check out the dnrTV episode for a full walkthrough.

    If you have questions, you can post them to the Mailing List.

    Where can I get it?

    First, install NuGet. Then, install AutoMapper from the package manager console:

    PM> Install-Package AutoMapper

    https://www.cnblogs.com/JustRun1983/p/3944173.html

    一. AutoMapper解决了什么问题?

    要问AutoMapper解决了什么问题? 难道不是对象映射转换的问题吗?
    当然是,不过我们可以问深入一些,为什么项目中会出现大量的对象映射转换?(以下对于非MVC项目也适用)

    在现代的软件开发中,项目的层级更加的细分,而不同层级之间对于对象的需求是有区别的,这就需要在不同层级间传递数据的时候,必须要转换数据。

    举一些实际具体的例子:
    在持久层(数据访问层), 我们的User对象,可能是一个包含User表中所有字段的数据的对象,甚至包含了用户的Password信息。而在界面层,我们只是需要显示用户的name, email,不需要Password这些额外的信息,同时,它还需要用户的考勤信息,而这个信息来自于另外一张表。
    这个例子中,能够发现不同层之间,我们对于数据对象的需求是不同的。
    每个层都做了它们职责范围内的事情:
    持久层关注数据,所以只提供数据对象,它无需知道外层如何使用这些数据对象,也无法知道。
    界面层关注数据的呈现,它只关注它要显示的数据。

    那么问题是,谁来弥补它们之间的鸿沟?DTO(Data Transfer Object)——数据传输对象。而AutoMapper就是解决其中涉及到的数据对象转换的工具。

  • 相关阅读:
    vue 中简单路由的实现
    Vue中对生命周期的理解
    内存泄漏
    前端工程化
    exports 和 module.exports 的区别
    Nodejs的url模块方法
    MongoDB 的获取和安装
    Anjular JS 的一些运用
    移动端vconsole调试
    安装fiddler时,电脑浏览器没网
  • 原文地址:https://www.cnblogs.com/chucklu/p/5289356.html
Copyright © 2011-2022 走看看