AutoMapper is one of the essential tools in my ASP.NET MVC toolbelt. I use it on every MVC project I do. It’s saved me countless lines of code over the years. And yet, there’s always been one thing that bugged me about it: it violates the idea of "common closure." I’ve built a better way to handle this, but as my friends have
accused reminded me, I might have forgotten to share this approach publicly. Until now.
With AutoMapper, you typically place your mapping configuration in a completely separate profile class, which creates an artificial barrier between two things that are likely to change together: your view model and its mapping definition. I came up with an alternative many years ago, but as my "friends" have pointed out, I apparently haven’t blogged it or talked about it openly before my Pluralsight course. To try and make up for that serious misstep on my part, I’ve extracted the relevant part of my Pluralsight course and made it available for free on YouTube. You can check it out here: ASP.NET MVC – Better Conventions for AutoMapper.
Full disclosure: this is a small piece of my full course, and the full course does require a Pluralsight subscription, and I do indeed make money if you subscribe and watch my course.