BT

Using Custom Conventions In .NET

by Roopesh Shenoy on Aug 27, 2012 |

Conventions Over Configuration approach used in several places by .NET designers to avoid excessive configuration. While the default conventions are helpful in getting up and running quickly, it can be useful sometimes to change the default behavior. We look at a few examples.

There are normally ways to work around the conventions for one-off cases by explicitly setting up the configuration, but what if you want to change the conventions themselves? These are some of the things possible -

  • Dino Esposito shows how the convention around ASP.NET MVC Controller names work, and how they can be modified
  • The convention for View locations in ASP.NET MVC can be changed if you use a Custom View Engine
  • Several conventions are used in Entity Framework CodeFirst, such as property that maps to the ID column and which class maps to which table automatically. These can be changed.

We have already covered Extensibility points in ASP.NET MVC earlier which provide several other opportunities to introduce your own desired conventions. 

The approach can be used with several third-party libraries as well. For example - 

Identifying where to stick with the default convention, and when not, is a matter of judgement. Using custom conventions in appropriate places can definitely make your code more maintainable. 

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT