Code Monkey home page Code Monkey logo

Comments (2)

krispetkov avatar krispetkov commented on July 24, 2024 1

I'm also interested in this question. But almost a year and no answer...

@malohr Did you find a solution to your question?

from cleanarchitecture.

ardalis avatar ardalis commented on July 24, 2024 1

Sorry for the over long delay in responding.

Short version: I agree with the referenced article.

Longer version:

  1. If you have very simple crud, with no nested collections, you can just use DTOs and yes, even AutoMapper. You can probably even just use entities directly (again if the types have no relationships and if all you need is CRUD).
  2. If you have to do custom stuff in your AutoMapper config beyond renaming a column or saying something is optional, you probably shouldn't be using AutoMapper for that task.
  3. AutoMapper is often more useful to go from domain entities to DTO types than the other direction.
  4. A lot of the pain involved in the examples that article outlines is related to the lack of using an Aggregate with proper encapsulation. If instead of mapping the child collection using AutoMapper and then worrying about deleted/updated collection items, the code in question should have been loading the aggregate and then calling methods on it to modify its state based on changes that had been made. Updates can just be made to the child items directly; adds and deletes should be made through the aggregate root which then is saved in its entirety.
  5. If you're building a web app/API you may need to consider how you want to handle updates, in terms of chunky vs. chatty. You probably don't want to expose a separate API endpoint per property to update, but it may be helpful to know, when a DTO is offered, which properties the client is attempting to change. You probably don't want to try and save the state of every piece of the aggregate, every time, especially if there are domain events or other behaviors associated with them that would be fired even if it wasn't actually changed (or now you must add code to detect changes in these methods). In short, some thought should go into this scenario so that you can balance encapsulating your design with practical use of the external API by client code. And in any case you probably don't want to use AutoMapper for your updates and deletes. You might get away with it for Creates but even then I'd be careful.

from cleanarchitecture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.