3

I recently worked at HP doing several ASP.NET MVC3 projects as I came from a software background I was relatively new to the inner workings of MVC3 as well as the best practices.

During this time I somewhat adapted the coding style of fellow co-workers and ways of designing my pages that I still stick with to this day. With all of this in mind my main question is what would anyone recommend for learning material; books/videos/tutorials. I can learn from any of those resources and I would love to know that I am coding properly.

I have several projects under my belt and many large scale business solutions that I have coded using Razor and ASP.NET but there are times where I feel that what I am doing is either very hacky or just an inefficient way of coding things. The larger the project is the more difficult it becomes to add new features because of this.

I think this is my lack of experience in coding but at the same time I would like to overcome this and I feel that with the mass experience I do have with MVC3 I could adapt to a easier style or design pattern that would help me not only optimize my code but become a much better web developer. If anyone has any suggestions on books or training sites or anything please let me know as I would love to get better.

Thanks in advance to anyone that has been in my shoes and is willing or capable of recommending anything!

2
  • 1
    This is very subjective. I would say specific samples may be needed outside of say steve sandersons MVC3 book. So many sites have code smell in their samples even the nerd dinner project. I would post here specific questions on what you are doing and then we can help on specifics. Commented Nov 25, 2011 at 5:52
  • I can see how you would think that the more I look at it and I think that is why I am confused at times about my ability to write proper code. I don't really know how to show examples unless I paste controllers/models and views for people to look at, would that be more practical? I just feel that there is a better practice such as design patterns such as SOA and others that would push me to develop in a more fundamentally structured way. Commented Nov 26, 2011 at 4:34

2 Answers 2

2

I was dealing with the same issue and found it useful to make a mind map. While it's impossible to give you a full understanding, I can try point you in the right direction with some basic ideas.

download/view (http://www.xmind.net/share/highroad/mvc3-design-pattern/)

Are you familiar with design patterns? Well they exists with MVC applications too :)

If you want to talk the talk and understand what people including myself are talking about, you would need to know the typical design patterns that come with building what they call enterprise level applications. These design patterns are the only real way to begin to understand the concepts.

These patterns structure complex business logic in ways that have become the tried and tested solutions (design patterns) to the design challenges the developer's face.

In the diagram notice there are 3 main layers:

  1. Presentation Layer
  2. Business Logic Layer
  3. Data Access Layer

Some of the highly used design patterns when dealing with Model View Controller in ASP.NET include:

Business Logic Layer Design Patterns:

  • Active Record. Models relate exactly to the database like in lightweight frameworks e.g. Ruby on Rails). When creating new MVC3 application with ASP.NET and scaffolding views and controllers, this is how it sets it up. Is perfect for less complex applications. So why not just use Ruby on Rails? I would
  • Domain Logic Layer. Uses MVC with the controller containing very little code and create lots of extra models that can do complex logic, the MVC is only for presentation. Often with this style of layer, a lightweight layer called a Service Layer can be used to call all the functions in the Domain Layer from the controllers i.e. the controller calls the method in the Service Layer class which calls the domain layer. This design pattern seems to be very popular with people who enjoy object oriented programming. See link below to my (quite basic) project designed using Domain layer.

  • Transaction Script - Use the controller to do a lot of the logic work per action, the problem is a lot of actions need to do the same things so there will be code repetition

For the Data Access Layer:

  • Something like entity framework models combined with a repository which can perform any SQL queries you need.
  • Not going into all the patterns for this layer but they include: Data Mapper
  • With simple apps, there is no real data access layer, it only becomes necessary if you use the Domain Layer in the business layer (which usually is the case)

Depending on what structure your application takes, your Models will mean very different things. In general they will not be models linked to the database (the default when creating a new app makes them like this). Instead they will be ViewModels which are only responsible for holding data that each of the views will need.

I have created a ssample app which you can see here.

https://github.com/testbrian/enterpriseframeworksB

Sign up to request clarification or add additional context in comments.

Comments

1

I don't know if this is an example of an enterprise solution, but I have learned a lot from the techniques found in RaccoonBlog. I like how the Layout.cshtml and other razor files use RenderAction to modularize the views.

The project is an example of MVC3 using RavenDb, but it's also one of the best real world applications I've seen since it's actually used in production.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.