ASP.NET MVC Model View Controller C# sharp .ner [dot net]
ASP.NET MVC
• A new way to build highly4testable apps on
top of the ASP.NET Framework
• An alternative to using RAD Web Forms
MVC Design Pattern
• Conery, Hanselman, Haack, Guthrie
define it as…
● An architectural pattern used to separate an
application into three main aspects
• Model. Set of classes that represent data and
business rules for how data can be changed and
manipulated
• View. Application’s user interface
• Controller. Set of classes that handles
communication from user, overall application flow,
and application4specific logic
ASP.NET MVC
• ASP.NET MVC 1.0
● Requires ASP.NET 3.5 / Visual Studio 2008 SP1
● Download Microsoft ASP.NET MVC 1.0 from
http://asp.net/mvc
● What we will use this session
• ASP.NET MVC 2.0
● In beta
● Will be part of Visual Studio 2010 / ASP.NET 4.0
Why Separate Concerns?
• Makes your app code more…
● testable
● modifable / refactorable
● reusable
● reusable
● maintainable
● scalable
What’s Wrong with Web Forms?
• Nothing…but…
● Web forms don’t allow as precise control over
“separation of concerns”
● Web forms are difficult to test ● Web forms are difficult to test
● Search engine optimization (SEO) issues
What Web Forms & MVC Have in
Common
• Both hosted in Visual Studio
• Both run on IIS
• Both use .aspx pages
Both can use Master pages
● Both can use Master pages
● though you can use a different view engine if
you’d like in MVC (NHaml, Spark, Brail,
NVelocity, etc.)
• Both can use any data access framework
(ADO.NET, LINQ, Entity Framework, etc.)
Basic Tenets of ASP.NET MVC
• Convention over configuration
• Don’t repeat yourself (DRY)
• Pluggability whenever possible
• Try to be helpful, but get out of the
• Try to be helpful, but get out of the
develper’s way
ASP.NET Project MVC Anatomy
• Models
• Controllers
• Views
• Shared
• Shared
• Content
• Scripts
Building MVC Application Demo
• Rough steps we will follow
1. New ASP.NET MVC Project
2. Delete Home files
3. Add model using LINQ 2 SQL
4. Add repositories
5. Add HomeController
6. Create Views
7. Add support for drop4downs
8. Add validation support
9. Add unit tests
ASP.NET MVC Pluses
• A new way to build highly4testable apps on
top of the ASP.NET Framework
• No post4backs
• Requests map to methods rather than pages • Requests map to methods rather than pages
• SEO4friendly URLs
• Supports TDD and Unit Tests
• Encourages use of design patterns and best
practices
ASP.NET MVC Minuses (Why Not)
• Not as RAD as using Web Forms
• No drag and drop experience
• Doesn’t build on all your experience with
ASP.NET server controls ASP.NET server controls
• Encourages use of design patterns and
best practices
No comments:
Post a Comment