views:

813

answers:

6

Hi,

we are building a new web application using Microsoft ASP.NET MVC2 and Entity Framework 4. Although I am sure there is not one right answer to my question, we are struggling to agree a VS2010 solution structure.

The application will use SQL Server 2008 with a possible future Azure cloud version. We are using EF4 with T4 POCOs (model-first) and accessing a number of third-party web-services. We will also be connecting to a number of external messaging systems. UI is based on standard ASP.NET (MVC) with jQuery. In future we may deliver a Silverlight/WPF version - as well as mobile.

So put simply, we start with a VS2010 blank solution - then what? I have suggested 4 folders Data (the EF edmx file etc), Domain (entities, repositories), Services (web-services access), Presentation (web ui etc). However under Presentation, creating the ASP.NET MVC2 project obviously creates it's own Models folder etc and it just doesn't seem to fit too well in this proposed structure. I'm also missing a business layer (or does this sit in the domain?).

Again I am sure there is no one right way to do it, but I'd really appreciate your views on this.

Thanks

A: 

What makes sense to you and your team?

What folder the code is in means nothing ( besides minor namespace generation ) and can be easily changed by dragging and dropping.

Right now organization barely matters, you have so little files its easy to browse around the slution. Once your 6 months in and you have 1000s of files thats when you'll need to start thinking about organisation.

With my own personal projects I dump everything into a single project, at work I have a 17 project solution and 50 folders. Code is code.

jfar
A: 

I believe you are right to consider the project structure (and namespaces) at this early stage. Although jfar's point is well made how often are you given the luxury to restructure your projects and namespaces before your first release? Even something as you suggest is better than throwing everything into the same project - surely?

mvole
A: 

Jfar is correct. It doesn't matter at this point what structure your solution takes. You'll have plenty of time to rearrange the solution later. I've done many small MVC applications and one large one and I'm still evolving how I prefer to structure the projects/solutions.

As far as structuring and MVC project, the only folder that really matters is Views. I have started to break away from the /Controllers and /ViewModels folder structure and grouping things by domain concept. If Student is one of your domain concepts, I'd have a Students folder in the domain project, in the MVC Views folder, in the services project, etc. All the domain classes, view models, controllers, etc would go under the same folder name (in different projects). That way you always know directly where to go to if you want to modify Student related code.

Also, we have a Web project that hosts the views and a separate class library project that contains the controllers. Most of my solutions have 12-30 projects.

Ryan
"Also, we have a Web project that hosts the views and a separate class library project that contains the controllers."You think this is good? Controllers use system.web, system.web.mvc, routing and similar namespaces, which are most likely to be found in the Web project. I just prefer having class libraries without referencing system.web or system.web.mvc, I always try hard to achieve that."Most of my solutions have 12-30 projects."Huh? Again, is that really necessary?
mare
Ryan
Also, sometimes we have a project with only one class, but it's a shim between our own code and a third party library. We'd rather write against a wrapper interface so that we can swap out libraries later. Putting the shim in another project forces us to write to an interface. For instance, many of our projects require streaming market quotes so we write to an IStreamingQuotesProvider, then we've have shims to work with DTN, ProphetX, and BarChart because different departments have different subscriptions but they all use a shared domain.
Ryan
A: 

You can watch this video by Rob Conery for an idea of how to structure your MVC project: http://blog.wekeroad.com/2010/04/19/tekpub-starter

http://tekpub.com/production/starter

HTH

mare
A: 

Wanted to add - it's not so important how You organize Your folders/solution, it is important how You organize Your code.

So - If Your app won't be properly layered using fancy techniques like dependency inversion, won't be neat and testable - it won't matter if You put stinky code in one or hundred folders. You won't be able to migrate from sql to Azure, from mvc to silverlight.

Arnis L.
Thanks Arnis good point.
Nick
A: 

How do you get Visual Studio Tooling i.e. Add Area and Add View to work for class libraries

Dan