views:

75

answers:

3
+1  Q: 

MVC Architecture

I know similar questions have been posted before, but I have specific requirements that make this as far as I can find unanswered.

The project wants to have a typical 3-tier architecture, but they want the data layer to be abstracted by Entity Framework, the presentation layer to be MVC 2 and the application layer to be simple class library.

Do those components (EF and MVC) fit into that architecture.

Note: the project would follow a TDD methodology.

Any help is appreciated.

+3  A: 

Absolutely.

Any good demonstration/articles on ASP.NET MVC Web Applications follow this architecture.

Typically your solution would look like this:

YourProject.Model (Class Library with POCO's - domain objects)

YourProject.Repository (Class Library with Entity Framework).

YourProject.Services (Class Library acts as mediator between Repository and Controllers)

YourProject.MVC (MVC2 Web Application)

YourProject.Tests (Unit Test Project - typically 1 project per tier)

To answer your questions, the Repository abstracts the data from the other modules, the presentation layer is MVC2, and the application layer could be built into the Services module, or have another module altogether.

Of course MVC fits beautifully with TDD, you can mock your controllers and test the class library just like you would test any class library.

Check out Rob Conery's MVC Storefront series on www.asp.net - best video series ive ever seen.

Good luck!

RPM1984
So my models would be in `YourProject.Model`, so the Models folder in the MVC app could be empty/removed and I do ll my ModelBinding to the POCO's? Finally the DataAnnotation attributes would be on my POCO's as well?
I like to keep the Models folder in the MVC add just for ViewModels (combined domain objects to simplify views). You can use DataAnnotations on your POCO's, the only issue is that you have to reference the System.Web.Mvc assembly - some people dont like this, but i personally dont see an issue with it. Just because youre adding a reference to an assembly that is typically used on the web tier, doesnt necessarily mean you're going against any architectural principal.
RPM1984
A: 

Yes, you can definitely implent a 3-tier architecture using MVC with EF. MVC will provide both the Business Logic layer (via Controllers) and also the Presentation layer (via its View Engine)

Would suggest you create a 2 separate projects : - One to contain Models (Data layer with EF) - The other to contain Controllers and Views (Business Logic and Presentation layer respectively

You could put the views into a separate project if you want to separate it out completely, although that's harder than separating the Models out.

Brendan
A: 

You should look at ContactManager sample with eight section tutorial on the ASP.NET MVC website, it's implemented with a repository class so data layer is abstracted.

Tiendq