Building a Content Management System Pt 3 – The Repository Pattern

When developing applications that made use of a database, one of the key features in my designs has been to create an intermediary class that handled the nuts and bolts of the data handling and presented the app code with a consistent interface regardless of how the data was being sourced.

The Data Access Layer (DAL) was mainly coded by hand but once it was it was done and followed the defined interface future enhancements were simple enough. The downside though was it often required a substantial amount of work to get to that point.

With the additional time I’ve been spending working on the home brew CMS, I found a great article on MVC that included a section on the Repository Patten which leveraged .Net features in a way that made creation of a DAL even easier. I’d seen articles about the Repository Pattern in the past but this one has the best set of examples I’ve ever seen to help developers migrate from their old designs to the new.

Admittedly I needed to spend a bit of time going over the example again and again to see how I’d benefit from it but once I began refactoring my code it became almost revelatory. The combination of LINQ, Entity Framework and Generics made the process not only easier for me to implement the DAL but the code cleaner and quicker to enhance. For someone who was used to building fairly substantial objects to handling data sources, this is a boon to reducing your workload and allowing you to focus your development elsewhere.

So for anyone looking at MVC and/or dealing with data, I highly recommend checking the article out.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.