Sharing the model
We have explored strict layering and how to apply the DIP, but we still have multiple models. An alternative to copying models from one layer to another is to share a model between multiple layers, generally as an assembly. Visually, it looks like this:
Figure 14.9: Sharing a model between all three layers
Everything has pros and cons, so no matter how much time this might save you at first, it will come back to haunt you and become a pain point later as the project advances and becomes more complex.
Suppose you feel that sharing a model is worth it for your application. In that case, I recommend using view models or DTOs at the presentation level to control and keep the input and output of your application loosely coupled from your model. This way of shielding your lower layers can be represented as follows:
Figure 14.10: Sharing a model between the domain and data layers
By doing that, you will save some time initially by sharing your...