Comments (2)
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.
Sorry for the over long delay in responding.
Short version: I agree with the referenced article.
Longer version:
- 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).
- 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.
- AutoMapper is often more useful to go from domain entities to DTO types than the other direction.
- 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.
- 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)
- Update to target latest net8 for Nov 2023 release HOT 1
- Api.Contracts project HOT 2
- Two sets of templates - Back end focused (Current [End Points]) and Front end focused (Blazor Web App) HOT 2
- Template Generated Solution Will not Build or Update HOT 2
- Please support domain event publishing of 'EntityBase<TId>' HOT 3
- Template Doesn't Work and Breaks Other Projects HOT 1
- Open the Discussions area in Github area so people can discuss the template and the whys
- Why is this repo using AutoFac instead of .NET's own DI infrastructure? HOT 3
- Handling Third-Party Authentication and Role Synchronization in DDD and Clean Architecture HOT 1
- GetContributorByIdRequest - Filename should probably match the classname
- Why is the implementation of the DeleteContributorService in the core layer? HOT 2
- Test case ReturnsTwoContributors() fails HOT 6
- Replace Autofac with Vanilla dotnet DI HOT 3
- Renaming Enhacement in Web Project. HOT 3
- Update Sample to Latest Version of Template HOT 4
- 404 when launching the project HOT 2
- Error when launching the newly created project from template HOT 2
- Add More Warning as Error Checks
- Mixed SharedKernel : Clean.Architecture and Ardalis HOT 1
- ProjectItemMarkComplete test fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cleanarchitecture.