An Ideal Folder Structure for .NET MVC [closed]

蓝咒 提交于 2019-12-02 15:31:47

I have found it simplifies deployment to have the website project contain only content (no compiled code).

Something like:

Web.Site project

   Content
      Images
      Css
   Scripts
   Views
   web.config

And move all compiled code into another project:

Web project

   Controllers
   Filters
   Models
   ...

Then, you can treat everything within the Web.Site project as needing to be deployed, and all required assemblies will be in Web.Site\bin.

Whether you are doing simple xcopy deployment, or using WiX to build an MSI package, this will make life a little easier.

I second the two project approach. Jimmy Bogard has a nice post on the approach as well (make sure to go through all the comments).

I personally find that when I'm working on a part of an application I use related services, controllers, repositories, etc.. and when you put each of these files in a different folder it can get tedious going back and forth and finding them. After some playing around I've been following this format:

AppName.Web.UI

Scripts
Content
View

AppName.UI.Core

Attributes
Filters
Formatters
Helpers
Models
  Company
     Interfaces
       IController.cs
       IRepository.cs
       IService.cs
     ViewModels
       ViewModel1.cs
       ViewModel2.cs
     Controller.cs
     Repository.cs
     Service.cs
  User
    ....
Plugins (mailchimp, Twitter OAuth, etc..)
Global.asax (define all the code here rather than in the UI project)

Test Project

  ...

I think it depends how large your project is as to whether you further break down and use Interface and ViewModel sub folders. Its not perfect, but I've found it meshes better with the way I think.

The case can also be made to put your services and repositories into a third project (AppName.Core), leaving the AppName.Web.Core project encapsulating only Web relates parts (Attributes, Controllers. ViewModels, etc..). Again that really relates to the complexity of the project.

So long as it's clear where things are, it doesn't matter much. I think it's just a matter of being consistent within your organization/group.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!