strike_noir
strike_noir

Reputation: 4174

In what folder should I put my extension methods in ASP.Net MVC?

Like the title said, In what folder should I put my extension methods in ASP.Net MVC?

What is the best practice for this?

Upvotes: 27

Views: 9931

Answers (1)

matt
matt

Reputation: 9412

I don't believe that there is a standard best practice to follow, but I usually do one of two things:

  • For smaller projects, I'll simply create an "Extensions" folder, and add the various extension classes to there.
  • For larger solutions, I'll have a separate project named something like ProjectName.Extensions, and within that project, I will have a folder structure that mirrors the namespaces of the classes I'm extending. For example:

ProjectName.Extensions/System/StringExtensions.cs ProjectName.Extensions/System.Web/HttpContextExtensions.cs ProjectName.Extensions/System.Xml/XmlWriterExtensions.cs

And so on...

Regardless of which approach I take, in both cases I'll name the class ClassNameExtensions.cs (e.g., StringExtensions.cs, ListExtensions.cs, etc.).

Upvotes: 36

Related Questions