Rules of thumb for refactoring

Consider refactoring in these cases:

  • When a class’s net length is above 300 lines
  • If the number of injected dependencies (services) exceeds 5
  • If the number of arguments for a method exceeds 3
  • It adds invaluable safety if you have unit tests for the code being refactored. If you don't have unit tests for a piece of code, before heavy refactoring is probably the good time to create them.
  • Try not to over-engineer things. A typical and simple to detect sign of an over-complicated system is if you have classes that are almost exclusively proxying calls to other classes.

Renaming a project

You should do the following steps to rename an existing .NET project (including an Orchard module or theme).

  1. Make a backup or commit to source control before attempting the rename.
  2. Rename the project from inside Visual Studio. This will change the project's name in a lot of manifest files.
  3. Search and replace the project's name in all files of the project or even of the solution (if you project's name is not a unique text be careful). This will rename all namespaces too.
  4. Search and replace the project's name in the project file (.csproj file). This will rename the project's default root namespace and its resulting assembly's name.
  5. Rename the project's folder (if it has one) to match the project's names. You'll have to re-add the project file under its new location to the solution as well as to other projects' references (if any).

This page is part of the Orchard Dojo Library!

This page and many others here are part of the open-source, portable package of Orchard 1.x goodies: the Orchard Dojo Library for Orchard 1.x. The Library is freely accessible by anyone; just go to its repository to download its full content (you can even download the textual content of the Library as a big concatenated document in HTML), file issues or fork it! You can even edit it online on Bitbucket, just click on the Edit link in the upper right corner!

Note that the Library also has an Orchard Core version, check it out here!