Summary
Object mapping is an avoidable reality in most cases. However, as we saw in this chapter, there are several ways of implementing object mapping, taking that responsibility away from the other components of our applications. One of those ways is AutoMapper, an open source tool that does that for us, offering us many options to configure the mapping of our objects.
Now let's see how object mapping can help us follow the SOLID principles:
- S: It helps extract the mapping responsibility away from the other classes, encapsulating mapping logic into mapper objects or AutoMapper profiles.
- O: By injecting mappers, we can change the mapping logic without changing the code of their consumers.
- L: N/A.
- I: We saw different ways of dividing mappers into smaller interfaces. AutoMapper is no different; it exposes the
IMapper
interface and uses other interfaces and implementations under the hood. - D: All of our code depends only on interfaces, moving the implementation...