Help needed for improvement
See original GitHub issueHi @kgrzybek , I am trying to add Automapper to map the request to command, which makes the code look much cleaner. But on every command you have a constructor that set’s values. Would it be fine if i change it like this
So the the above helps in achieving this.
var proposeMeetingCommand = new ProposeMeetingGroupCommand();
_mapper.Map(request, proposeMeetingCommand);
await _meetingsModule.ExecuteCommandAsync(proposeMeetingCommand);
Please let me know your thoughts/ suggestions
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
20 Areas of Improvement for Employees
Set specific, measurable and achievable goals for yourself. This can help you stay focused on what you want to achieve and helps make...
Read more >How To Answer “What Areas Need Improvement?”
Our hiring expert gives advice on how to answer “What areas need improvement?” - Interview question, with sample answers and expert tips.
Read more >9 Areas of Improvement for Employees to Work On [2023]
Encourage your employees to level up at these 9 areas of improvement and push your business development one step further!
Read more >Top 30 Ways to Improve Work Performance [2023]
Explore the top 3 proven ways to improve your work performance. Including additional 18 ways and 10 actionable tips for HRs.
Read more >24 Excellent Ways to Improve Work Performance
Discover 24 awesome tips to improve work performance and be more productive and efficient without taking unwanted stress and an overwhelming ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With full respect for Jimmy’s Bogard work and his Automapper library - do not use it (and any of mapping libraries) in more complex projects - this is my opinion and advice.
Commands and Domain Events should be immutable. Public setters and parameterless constructors remove encapsulation - this is nightmare of most codebases which I see regularly. Don’t do it.
Private setter is much better solution but still not ideal. It breaks immutability *intention". Additionally, as far as I know, there is performance difference in CLR between no setter and private setter (I cannot find any reference now).
I used Automapper long time ago (6-7 years maybe) but I stopped. For me creating mapping in code is not a deal. It is easy and quick and with removed “primitive obssesion” I have a lot of compile-time checks and support. Sometimes more code is not bad. I don’t want to use external library in this case.
To sum up - don’t use mapping library or use mapping library which supports private setters. I strongly recommend former.
I think we all agree that using mapping library in Command handling is not good idea. Let’s move to Queries 😃
If you use microORM like Dapper you have everything out of the box - projection to type, selecting only needed columns etc. Mapping library is not needed.
So maybe one of the reason to use it is mapping Domain Entity to DTO? I don’t think so. Domain Model is optimized for writes, not reads. You should not use it for reading. In this application you cannot even do it because all fields are private.
So if you don’t have true Domain Model and you use EF as data access tool to Data Model why not to return data models (EF entities) directly? EF supports projections I think.
Maybe I am missing something so please add some reference to repository or good article why is better to use Automapper in cases which I described.