All The Write Stuff

Kevin Hopkins

Making the Internet work for you

An Insufficient Separation of Concerns

Many companies I have worked for recently don’t gain the full benefits of ASP.NET MVC, Entity Framework and Agile. Let me explain.

MVC stands for Model-View-Controller and is an application architecture or design pattern that splits up an application into distinct layers known, unsurprisingly, as Models, Controllers and Views.


User interaction with an MVC application follows a natural cycle, wherein a user takes an action on a web page which launches an http request which is handled by a Controller and in response the application changes its Model, persists or updates some data in a database and then delivers an updated View via the Controller to the user via an HTTP response. This is a good fit for web applications using HTTP.

Most web applications combine HTML mark-up, client side scripts, server side executable code, domain classes, object relational mappers, databases etc. These map very well onto the MVC design pattern splitting the application up into discrete layers leading to a strict and beneficial separation of concerns.


This layering is based on a separation of responsibility where:

  1. user interface issues are in the Views and nowhere else,
  2. business entities and logic are in the Model and nowhere else,
  3. transaction processing logic is in the Controllers and nowhere else,
  4. data persistence is in data layer limited to this and nothing else.

As a result components in each layer are also loosely coupled. That is, each layer has a service interface to, but no tangible dependency on, its neighbouring layer. Each layer is essentially a black box that can be swapped out with a different implementation without breaking the overall application.

Compare this with the event driven SMART UI pattern behind ASP.NET Web and Win Forms development. Here there is no separation of concerns. Web and Win forms are relatively easy to write but difficult to read, maintain, extend and test. Due to the tightly coupled architecture testing become challenging, time consuming and resource heavy as source code grows overtime. Changes lead to frequent end-to-end regression testing of the entire application which is painful and costly.


MVC applications are more time consuming to write initially but they are more readable and easier to maintain and extend because of the loosely coupled architecture, tidier nature of the code, and a strict separation of concerns. This facilitates automated testing of layers interdependently of each other through use of fake or mock implementations of interfaces which simulate dependencies and provide predefined data sets and repeatable test scenarios. Automated testing in turn increases the tempo of testing and facilitates continuous integration and release of code changes in short iterations which fits well with Agile application lifecycle management methods.

Agile is essentially about running software development as a rapid and adaptable process of discovery and resisting the encumbrance and restrictions of excessive forwarded planning. It is about short iterations of development effort with frequent feedback and regular releases of small increments of business value to stakeholders usually at the end of fortnightly sprint cycles. The main effort is on domain driven development focusing on representing real world entities as objects in the Model and business logic as methods on those objects. Entity Framework is the glue that permits these objects and their state to be persisted in the database. MVC and Entity Framework goes hand-in-hand with Agile particularly where a separation of concerns permits automated testing and continuous integration.

The business and commercial benefits that flow from the ASP.NET MVC, Entity Framework and Agile are:

  • Clients get the right product because Agile encourages flexibility to change and the product is maintainable and extensible allowing requirements to emerge and evolve during development.
  • Client gets a quality product as testing is incorporated throughout development and not just at the end of development.
  • There is less development waste and rework as deviation and errors are identified early due to frequent product owner and client reviews and feedback thus reducing overall development costs.
  • Active involvement of a user representative and/or product owner, together with high visibility of the product and progress, and flexibility to change when needed, creates much better business engagement and customer satisfaction and thus more positive and enduring working relationships.
  • In terms of time, budget and scope, Agile helps to fix time and budget and vary scope. Flexibility on scope though, has to work both ways, and in a fixed time fixed cost project, the product owner or client must be prepared trade off items in the product backlog for any new items they wish to include.
  • The incremental nature of Agile permits early implementation of some functionality while product development continues and this facilitates a phased revenue stream which helps to reduce commercial risk.

Unfortunately, in many projects, organisations choose to make use of pre-existing databases with stored procedures containing much of the business logic. This leads to  "an insufficient separation of concerns" between the domain Model and persistence layer. The lack of a distinct MVC Model and separate business logic layer reduces scope for automated testing and continuous integration and diminishes the business and commercial benefits that could be available.


Companies considering the use of ASP.NET MVC and Entity Framework together with Agile for their future projects will benefit most on green field projects or on brown field projects where customers can be persuaded to adopt a big bang technology refresh and start from scratch. There is thus the opportunity to:

  • abandon legacy data and technical debt,
  • craft a discrete MVC Model and conduct domain driven development,
  • use Entity Framework Code First to generate the database schema from the MVC model,
  • adopt automated testing and continuous integration.

This helps development teams to fully embrace Agile to obtain the commercial and business benefits highlighted earlier in this article.

Loading