BT

InfoQ Homepage News Using Custom Conventions In .NET

Using Custom Conventions In .NET

Bookmarks

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
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.

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

Community comments

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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.