+1  A: 

Your solution/project structure looks pretty sound to me. If you've never taken a look at S#arp Architecture, you may want to. The main difference between your structure and S#arp's architecture is that S#arp's breaks out the Controllers, Services, and Repositories into separate projects. The main benefit of doing this is that it becomes easier to enforce boundaries on your dependencies (e.g. you won't accidentally access data access specific libraries from code in Core).

Other than that, your structure looks very similar to the one I tend to use for my projects. I also add an "Extensions" folder for extension methods, since those are sometimes hard to find a good place for.

Kevin Pang
So is your **Extensions** folder in your **Core** project, or do you put them in a more "Utilitarian" project that can be reused across other projects?
rockinthesixstring
+2  A: 

There is room for improvement.

Any of my solutions have 4 basic parts. The UI Layer, the Business Layer, Data Access Layer, and Utilities. Each part is a project.

My ultimate goal is to NEVER write code in more than one place but to reuse it.

UI and Data Access are obvious.

Anything specific to the project I am working on goes into the Business project.

The Utilities is what I call a common library. These are good helper functions that I can use in many projects. For example a function to aid in logging.

David Basarab
Do you put your Extension Methods in your Utilities project or in your Business project?
rockinthesixstring
+1  A: 

Nice Wiki.

I'm starting a new project, and this is structure i have begun with.

It follows the Microsoft Best Practices (Business, Data, Services, Presentation).

alt text

In my solution:

  • Business: domain/project-specific logic, and most notably POCO's.
  • Data: repositories. self explanatory.
  • Services: logic on top of repositories. i can add caching here, filtering, etc. My UI communicates to repository through Services, not directly to repository. (one-to-one dependency for UI).
  • Presentation: MVC application (TBD).

You'll notice I also have a habit of prefixing the actual project assembly name with the FQN.

I just like the look of it, plus in the Object Explorer it all looks nice and "tree-like".

Also i have a habit of putting a number in front of the folder, so it sorts according to "what needs what". In other words, everything depends on the business layer (so its on the top), repository only depends on business, services depend on repository and business, presentation depends on services and business, etc.

Of course, the above is a starting point. All i have right now is a repository which returns users, and services which apply logic on top of it (filtering).

Eventually i'll have more business projects, more repositories (one for each logical area of web application), more services (external API's, integration), and of course i have nothing in Presentation (im doing TDD).

I also like having the Dependencies all in one place (project folder).

For extensions, i have one class (Extensions.cs) for each project. In other words, i am "Extending" the repository, or "Extending" the user service, or "Extending" some UI functionality.

For test projects - i have test project per solution project.

That's my Two Cents (for what it's worth).

RPM1984
I really like this, but there's one concept that eludes me. Take the following for example `UI/Controller -> Service -> Repository -> L2S/DBML` If my `User` Poco is generated by the L2S Class, and I need to pass that object from the controller to the service, I would then need to include the L2S Class in my controller, which in turn defeats the purpose of separate projects... is that right or am I missing something? - Either that or I create an Identical POCO in the business model that can be passed between controller and service.
rockinthesixstring
POCO baby POCO. =) That's what my business model is for, EF projects the tables into my custom POCO's, which are passed around the app. Without POCO's though, yes you are right. If i wasnt using POCO's (i hate the word but i cant stop using it), i could rethink the architecture. Plus i dont use L2SQL anymore - EF all the way.
RPM1984
I've been looking at EF, but as I see it, it's just some advanced features over L2S. EF still creates your POCO's... so what you're saying is you create those same POCO's a second time in your Business model?
rockinthesixstring
@rockinthesixstring - no. By default, EF creates POCO's for you, in a hidden class called <ModelName>.edmx.designer.cs. This is part of the EF "Code Generation". But, i turn this feature off. So EF does nothing. You drop your tables on the EDM, and no designer file is created - you manually create your own mappings (not as hard as it sounds). So really, you kind of 'take over' the POCO generation in order to put it where you want and apply specific behaviour. L2SQL is good for "drag-drop-lets-go", but it lacks the features of a full-blown and mature ORM like EF/NHibernate (IMO).
RPM1984
The task of "Custom POCO's" is made easier with the VS2010 T4 POCO Generator, however this still chucks it one file (.tt), however i still use this, then c+p the code into my own classes - this way i avoid manual errors trying to map my db columns to poco properties.
RPM1984