Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Folder Conventions

ASP.NET MVC projects follow naming and folder conventions for Models, Views and Controllers. For other code (ex: Action Filters, Delegating Handlers, etc), is there a best practice as to where to locate these in the project's folder structure?

like image 864
Bullines Avatar asked Dec 12 '25 12:12

Bullines


2 Answers

A good way to find out is by checking out what the actuall best practices are is to see Open Source projects. IIRC the NuGet Gallery was written by the Asp.Net MVC guys, so it would serve as a good example for what they view as Best Practices while still being an actual product:

https://github.com/NuGet/NuGetGallery

It looks like they added their FilterAttributes, HtmlHelpers, etc. to the root of the project : https://github.com/NuGet/NuGetGallery/blob/master/Website/RequireRemoteHttpsAttribute.cs

Also, Phil Haack and David Ebbo worked on the Asp.Net MVC team, and you can check out their GitHub repos for what they like to do.

like image 55
Rob Rodi Avatar answered Dec 14 '25 09:12

Rob Rodi


There is no standard way as such. Different practitioners have put up various methods but all have some pros and cons. However, based on applicable design constraints, here are some pointers :

  1. Reusability

    If you want your Action Filters, Delegating Handlers etc to be reusable, then placing them in a dedicated folder in asp.net mvc webroot will do the job. That way all such filters will have global scope and can be used as needed.

  2. Pluggability

    If want to create a pluggable module out of the filters etc. It might be worth placing them in a separate DLL altogether. The library can be thought of as a black box which takes all contextual information as function inputs and can be reused as required. I liked the pluggable architecture of Orchard CMS http://www.orchardproject.net/

I asked a similar question sometime back on how to organize models in asp.net mvc project. Unfortunately didn't get much response. Models in asp.net mvc 3 areas

like image 39
amarnath chatterjee Avatar answered Dec 14 '25 09:12

amarnath chatterjee