Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
An Atypical ASP.NET Core 5 Design Patterns Guide

You're reading from   An Atypical ASP.NET Core 5 Design Patterns Guide A SOLID adventure into architectural principles, design patterns, .NET 5, and C#

Arrow left icon
Product type Paperback
Published in Dec 2020
Publisher Packt
ISBN-13 9781789346091
Length 762 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Carl-Hugo Marcotte Carl-Hugo Marcotte
Author Profile Icon Carl-Hugo Marcotte
Carl-Hugo Marcotte
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Section 1: Principles and Methodologies
2. Chapter 1: Introduction to .NET FREE CHAPTER 3. Chapter 2: Testing Your ASP.NET Core Application 4. Chapter 3: Architectural Principles 5. Section 2: Designing for ASP.NET Core
6. Chapter 4: The MVC Pattern using Razor 7. Chapter 5: The MVC Pattern for Web APIs 8. Chapter 6: Understanding the Strategy, Abstract Factory, and Singleton Design Patterns 9. Chapter 7: Deep Dive into Dependency Injection 10. Chapter 8: Options and Logging Patterns 11. Section 3: Designing at Component Scale
12. Chapter 9: Structural Patterns 13. Chapter 10: Behavioral Patterns 14. Chapter 11: Understanding the Operation Result Design Pattern 15. Section 4: Designing at Application Scale
16. Chapter 12: Understanding Layering 17. Chapter 13: Getting Started with Object Mappers 18. Chapter 14: Mediator and CQRS Design Patterns 19. Chapter 15: Getting Started with Vertical Slice Architecture 20. Chapter 16: Introduction to Microservices Architecture 21. Section 5: Designing the Client Side
22. Chapter 17: ASP.NET Core User Interfaces 23. Chapter 18: A Brief Look into Blazor 24. Assessment Answers 25. Acronyms Lexicon
26. Other Books You May Enjoy

Project: Mapper

This project is an updated version of the Clean Architecture code from the last chapter, which contains both a data model and a domain model. I used that version to showcase the mapping of both data to domain and domain to DTO. If you don't need a data model, don't create one, especially using Clean Architecture. Nonetheless, the goal is to demonstrate the design's versatility and encapsulate the mapping of entities into mapper classes to extract that logic from the repositories and the controllers.

First, we need an interface that resides in the Core project so the other projects can implement the mapping that they need. Let's adopt the second design that we saw:

namespace Core.Interfaces
{
    public interface IMapper<TSource, TDestination>
    {
        TDestination Map(TSource entity);
    }
}

With that interface, we can start by creating the data mappers. Since we are mapping Data.Models.Product to a Core.Entities.Product and...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime