Abstract

Convention over configuration is a software design paradigm which is used by many modern software framework including ASP .NET MVC and Web API. It’s also known as “Coding by Convention”.  It takes a lot of burden away from developers, which is otherwise required; to handle basic aspects of the application. For example, mapping of database tables with classes, or handling URLs etc.

Introduction

ASP.NET MVC (Model View Controller) very nicely showcases this software design paradigm via Visual Studio’s ASP.NET MVC Project template directory structure. ASP.NET MVC Project have three core folders “Controllers, Models and Views” as shown in Figure- 1 below.

Figure-1 Visual Studio MVC project folder structure

ASP.NET MVC framework’s folder structure is based on “Convention over Configuration” and that’s why practically, a class in Models folder can be safely assumed that there is a table with that name in the database. A Controller can be created with a <Name> with a suffix “Controller” (for example, EmployeeController, ProductController etc.) Similarly, an action method in Controllers folder’s controller class can be accessed with Controller class name (name without suffix Controller) for example, Details action method in EmployeeController by convention can be easily accessed via http://Your-Domain-Url/Employee/Details

Implementation

If there is no “Convention over configuration” paradigm; to make any such behavior work, developers need to specify/code some configuration rules to educate the application about interpreting a url and under which folder or where to look for the resource to serve that request.

Hence, having Convention over configuration is already baked into ASP.NET  MVC, Developers don’t need to write any code to establish communication mechanism among various application components. To have it function properly, conventions need to be followed and developers need to adhere to those conventions.

For example, all controller classes must reside under “Controllers” folder with <Controller> suffix as convention for example, Controller\HomeController, Controller\EmployeeController etc.
Views folder is known to have all the views and convention tells Controller where to look for a View(s) associated with a controller action method; as shown in Figure 2 below, each action method in Controller\HomeController refers to individual cshtml under “Views\<folder with controller name>”

Figure-2 Convention over configuration in Action
Hence, convention over configuration help developers to easily communicate with the ASP.NET MVC web framework by providing the pre-defined conventions as shown in Figure-3 below

Figure-3 Convention over configuration in action.

Note, that if you don’ follow the conventions correctly for example, create a controller class named DefaultController1.cs under Controller folder and build it; then Visual Studio IDE will not report any issues and it will build successfully.

Or simply move HomeController out of Controllers folder, under the project. Hit the route http://locathost/Home/About and you will get 404.

Building solution successfully doesn’t mean, that it will work.

No error was reported because as a developer you are given freedom to name your controller class etc. as per your wish; so you have freedom. But to have it working “Convention needs to be followed strictly” hence, it will not work. But once you adhere to the Convention by renaming DefaultController1 to “DefaultController” or moving HomeController back into Controllers folder; and you hit the route then it will start to function as expected.

Read this on C-SharpCorner

Abstract

Many times this question comes to our mind that is one technology totally replaced by new release or new version of technology. In this article I will try to explain about such and similar issues and I will share my industry experience not only what I have seen in India (largest IT Solutions provider to the world) but also in USA.

I consider this to be a very hot topic and good candidate of debate rather; but I will try to share my thoughts on such a burning topic. In this article I am not going to highlight or defame any technology; I am just going to put my perspective as I have seen, experienced and advised to various clients and software teams.

Why new Versions

“Change is Only Constant” this principle applies very well to the Software Industry, and I respect this over-flow of information. Because this gives me a reason to “Keep Learning and stay ahead of the Curve”. By saying so I didn’t mean that someone has to learn anything and everything you can get your hands on. NO, certainly not, but before I explain this any further let’s take a step back and understand “Why new Versions” keep coming.

We are fortunate that we have seen a complete transition of the software industry from Desktop to Web to Mobile, upcoming generations may not witness this great and life-changing shift. Also, I recall my days when I was working and studying software in 1995, no one imagined that there will be MVC, WPF, WCF, so many versions of .NET and SQL Server etc. The industry was happy with MS-Access, Fox-Pro, C, C++, and Oracle etc. But our needs keep changing, they evolved and then the shell is broken to have huge expansion and today we have all kind of software technology and server products from client side to server side to mobile and hand-held and many more. We moved from on-premise to Cloud, Machine Learning is helping to dictate patterns and suggest needs.

This is why software companies keep building latest and newest technologies to enable and empower the world to build for future. When they release a version of a technology or language and they discover some issues or new features in that then they release newer versions and this in a chain reaction process and it will not stop.

Oh, then I will die Learning

As per Darwin’s Evolution Theory “Survival of the Fittest”,”fit” refers to “best adapted to the current environment.Here you simply replace environment to Software Industry. I am one of you and I don’t recommend that everyone has to learn everything but what I suggest it stick to your technology of choice and have good knowledge on their offered tools and technologies and various versions and when to use which one.

Also, you don’t necessarily have to know every single thing. For example, I only focus on .NET and related technologies, if anything falls beyond this area then I am not bothered. To be more precise, I don’t know Microsoft CRM, SharePoint, System Center, SQL Server Database Administration and few more things like that.

But this is not my weak point because “I continue to build my .NET Muscle” and keep learning about what helps me build Enterprise solutions using Microsoft.NET.

So choose your area of interest and where you have invested and then keep learning in the similar field and then you will no longer find it challenging; because if you observed new versions come after every few years and that has to be otherwise it will be No Fun!

Hmm, so Isn’t MVC Replacing ASP .NET Web Forms

Such decisions are not final and have no concrete answers. Yes, the industry changed their needs and so new technologies such as MVC and WPF takes over. This definitely doesn’t mean that ASP .NET  Web Forms is replaced or it’s dead. If you know the Microsoft Web fundamentals MVC is based on ASP .NET and industry is trying to shift as and when they can from Web Forms to MVC and reap the benefits it offers.

Did you know that MVC is much older than ASP.NET? Yes, ASP .NET 1.0 was released in 2002 and MVC was created in 1979 originally named as “Thing-Model-View-Controller” but later simplified to be known as MVC.

In my view, I consider that there are now two technologies to build Web Solutions using Microsoft and based on your need you can pick one which works well for you. Usually, such technology selections are made by Architects assigned to the project.

So there is no such Golden Rule that every new or existing application has to be either created using MVC or migrated to MVC because MVC is latest and future of the web. Though it is.

Architectural Thinking – Brownfield Vs Greenfield Applications

All software applications you have worked or will work in future are either brownfield or greenfield.

Brownfield Development – When any existing or legacy applications needs to have new features or changes to address business needs; is known as the brownfield. In such situations, unless you are building new module or component you have less  / limited or no scope to use new architecture styles, patterns etc. The very reason of such limitations is because those old applications are build using an old version of technologies and latest versions of one technology/framework may not be compatible with old versions.

Greenfield Development – When a brand new project is being envisioned and no previous work is done in that or related area then it’s called Greenfield. In software industry, it doesn’t happen very often. But whenever it happens its Architect’s responsibility to figure out what is the best technology to address business needs.

Hence, it’s not appropriate to say that because MVC is so new hence every new web application must be made using MVC or if WPF is available in addition to Windows Forms so every desktop application has to be made using WPF. Whatever is the case neither ASP .NET nor Win Forms can be totally ignored.

Why and Why not Latest Technologies should be picked

First, let’s discuss Why Not

  1. Its brownfield and new technology don’t fit anywhere.
  2. If new technology or versions are introduced it will case a lot of build errors due to outdated references of non-supported library references.
  3. Business goals and software quality are not compromised by continuing to use current and available technologies like ASP .NET WebForms over MVC or Win Forms over WPF.
  4. You are not investing money in any extra off-the-shelf tools to handle issues which could have been handled by latest versions of a similar area of technologies e.g., MVC instead of ASP .NET Web Forms, or WPF over Win Forms.
  5. Many times team might not have a certain skill set which allows them to proceed with development using new technology options
  6. Many times budget allocation from a client may impact your decision to use and develop using latest technologies.
  7. If core/bestselling features of new candidate technology (MVC or WPF) are not being used at-least up to 50% then you have not achieved anything.
  8. Considering how soon client and business want to have an application ready, turns out to be major factor o dictate technology of choice.
  9. Client and business don’t bother how you do it; what matters is the end result and a workable/good – enough software.
  10. No way to use old legacy downstream applications with latest available technologies.

Why develop using Latest Technologies

  1. Greenfield software solution and no legacy or old piece of code is being used.
  2. The focus is more on Robustness, Testability, Object Oriented design, and quality. (This doesn’t mean previous technology can’t accomplish these; it’s about ease and inbuilt features and offerings).
  3. An amazing team with great skills to learn new technologies and adapt the changes.
  4. Company’s vision is to showcase products build using latest technologies.
  5. Client themselves want the solution to be developed using latest technologies and have the budget to support that.

Why MVC over ASP .NET Web Forms then

Note- this section assumes that you are aware of MVC benefits and general technical terms used below.

  1. Separation of Concerns is the core of MVC.
  2. Single Responsibility Principle is achieved by default.
  3. Unified and even better framework to work on WebAPI, Mobile, HTML 5, CSS3, Security, and Deployment (including Azure).
  4. Unit testing is easily achieved to have stable, robust and quality software solutions delivered continuously.
  5. Fast screen generation for CRUD operations via Scaffolding.
  6. Convention over configuration.

Summary

Based on my experience as an architect in the industry I would like to summarize that it’s very hard for any organization to keep up with latest version and technologies all the time because by the time you become comfortable with one version the newer is around the corner.

So if you are working on MVC 4, then see if you can learn and try some application being developed on your own. Or if you just happen to be in ASP .NET Web Forms world until now then I would encourage you to try converting that application into MVC for your personal benefit.

This will enforce you to learn new technology and apply those learnings; if you made some progress in that then in next interview you can proudly showcase your MVC knowledge and say that you migrated ASP .NET WebForms to MVC.

“Regardless of what you are using to make a living out of a job, you have to learn new ones to build a Career.”