BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Using Custom Conventions In .NET

| by Roopesh Shenoy on Aug 27, 2012. Estimated reading time: 1 minute |

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. 

Rate this Article

Adoption Stage
Style

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

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT