My simplest ASP.NET MVC 2 controllers make calls to my service level and map display models for objects using AutoMapper. Everything looks fantastic and there is no re-code.
However, when I get into a scenario where I have similar behavior , I have problems balancing the Single Responsibility Principle (SRP) with Do not Repeat Yourself (DRY). An example of this may be the need to add / edit vehicles, where some properties / behavior are shared and others are unique to a particular vehicle.
If I strive for really thin controllers (thus, observing the principle of common responsibility), I get repeated code both in views and in controllers with small variations (name, field labels, field visibility, dropdown values, selection criteria, etc. .).
If I strive for non-repeatable code, I end up adding too much logic to one controller / view and it gets bloated.
What are some ways to address duplicate code in controllers / views? I am not talking about database code that can be accounted for in the repository. I am not talking about business logic that can be taken into account at the service level. I am looking for tools and / or rules of thumb that will help me create the best solution in the scenario described above.
asp.net-mvc dry srp controller
Mayo
source share