Introduction to ASP.NET MVC 1.0
-
Upload
shiju-varghese -
Category
Technology
-
view
2.606 -
download
1
description
Transcript of Introduction to ASP.NET MVC 1.0
Shiju VargheseShiju Varghesehttp://weblogs.asp.net/shijuvarghesehttp://weblogs.asp.net/shijuvarghese
Session ObjectivesSession Objectives
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC Demonstrate programming using Demonstrate programming using
ASP.NET MVCASP.NET MVC
What’s wrong with ASP.NET What’s wrong with ASP.NET WebFormWebForm
ViewStateViewStatePage life cyclePage life cycleLimited control over rendered HTMLLimited control over rendered HTMLLack of Separation of Concerns (SoC)Lack of Separation of Concerns (SoC)UntestableUntestable
What is MVCWhat is MVC
A design patternA design pattern Acronym for Model View ControllerAcronym for Model View Controller Isolating business logic from UIIsolating business logic from UI Layering for UI layerLayering for UI layer Separation of Concerns (SoC)Separation of Concerns (SoC)
Separate content from presentation and data-Separate content from presentation and data-processing (model) from contentprocessing (model) from content
What is MVCWhat is MVC
View is just concerned about View is just concerned about presentation logicpresentation logic
Models represent the dataModels represent the data Controllers just handle Controllers just handle
application flow application flow You write less code and end You write less code and end
up with a more maintainable up with a more maintainable application.application.
Why a new modelWhy a new model
A lot of developers asking for it.A lot of developers asking for it. Simpler way to program ASP.NETSimpler way to program ASP.NET Enable separation of concerns and testabilityEnable separation of concerns and testability Model-view-controller presentation pattern is a Model-view-controller presentation pattern is a
time-tested pattern that scales with size and time-tested pattern that scales with size and complexitycomplexity
Complete control over Html generatedComplete control over Html generated
What is ASP.NET MVCWhat is ASP.NET MVC An alternative framework to ASP.NET Web An alternative framework to ASP.NET Web
Forms.Forms. More control over your HTMLMore control over your HTML A more easily testable frameworkA more easily testable framework Simply an optionSimply an option
Will not a replacement for Web FormWill not a replacement for Web Form Build on top of ASP.NETBuild on top of ASP.NET
Opinionated FrameworkOpinionated Framework Community Driven FrameworkCommunity Driven Framework Source code on CodePlexSource code on CodePlex
Goals of ASP.NET MVC Goals of ASP.NET MVC FrameworkFramework
Enable clean separation of concernsEnable clean separation of concerns Each component has one responsibilityEach component has one responsibility
Single Responsibility Principle (SRP)Single Responsibility Principle (SRP) Highly testable and maintainable applicationHighly testable and maintainable application
Testable by default (built with TDD in mind)Testable by default (built with TDD in mind) Red/Green/Refactor TDD Red/Green/Refactor TDD
Enable full control over the rendered HTMLEnable full control over the rendered HTML Enable clean URLs and HTMLEnable clean URLs and HTML
SEO and REST friendly URL structuresSEO and REST friendly URL structures
Goals of ASP.NET MVC Goals of ASP.NET MVC FrameworkFramework
Extensible and Pluggable framework.Extensible and Pluggable framework. Interface-based architectureInterface-based architectureSupport replacing any component of the systemSupport replacing any component of the systemSupport third-party view engines such as Support third-party view engines such as
NVelocity, Brail, NHaml NVelocity, Brail, NHaml Support user-provided front controller that Support user-provided front controller that
enable Inversion of Control containersenable Inversion of Control containers Build on top of ASP.NETBuild on top of ASP.NET Support static and dynamic languagesSupport static and dynamic languages Conventions and GuidanceConventions and Guidance
ASP.NET MVC doesn’t haveASP.NET MVC doesn’t have
PostbacksPostbacks View stateView state Control stateControl state Server-side formServer-side form Page/Control lifecyclePage/Control lifecycle
ASP.NET MVC still has…ASP.NET MVC still has…
Web designerWeb designer Master pagesMaster pages User controlsUser controls Membership/Roles/ProfileMembership/Roles/Profile GlobalizationGlobalization CachingCaching HTTP intrinsics objectsHTTP intrinsics objects
URL Routing URL Routing
Browser Request is mapped to controller Browser Request is mapped to controller action through URL Routing. URL Routing action through URL Routing. URL Routing route the incoming requests to controller route the incoming requests to controller actions.actions.
URL Routing uses Route Table that will be URL Routing uses Route Table that will be created when application first starts.created when application first starts.
Route table is setup in the Global.asax file.Route table is setup in the Global.asax file.
URL Routing URL Routing
How it worksHow it works
Browser
List.aspx(View)
Web Server
CategoryController(Controller)
http://myserver.com/category/List
http://myserver.com/category/Edit/5
Edit.aspx(View)
DatabaseEmployeee
(Model)
Request FlowRequest FlowBrowser requests /Category/Route is determinedController is activatedMethod on Controller is invokeController does some stuffRenders View, passing in custom ViewData
Request FlowRequest Flow
SummarySummary
Not a replacement for WebFormNot a replacement for WebForm Just an alternative optionJust an alternative option Not for everyoneNot for everyone
Build on top of ASP.NETBuild on top of ASP.NET Providers still workProviders still work
Membership, Caching, SessionMembership, Caching, Session
Views leverage .aspx and .acxViews leverage .aspx and .acx
Summary – Extensible Summary – Extensible FrameworkFramework
Replace any part with your ownReplace any part with your own All are pluggableAll are pluggable
ViewsViews ControllersControllers ModelsModels RoutesRoutes
Summary - Clean URL StructureSummary - Clean URL Structure
REST based ArchitectureREST based Architecture Fits with the nature of the WebFits with the nature of the Web
ASP.NET MVC exposes the stateless nature ASP.NET MVC exposes the stateless nature of HTTPof HTTP
Search Engine Optimization (SEO)Search Engine Optimization (SEO)
Showcase of live ASP.NET MVC Showcase of live ASP.NET MVC applicationapplication
http://http://stackoverflow.comstackoverflow.com// A Web 2.0 applicationA Web 2.0 application Q & A website for developersQ & A website for developers Blend of Wikis, Blogs, Forums, and Blend of Wikis, Blogs, Forums, and
Digg/Reddit Digg/Reddit OxiteOxite
Microsoft’s open source platform for CMS/BlogMicrosoft’s open source platform for CMS/Blog Used to develop MIX Online (Used to develop MIX Online (http://visitmix.comhttp://visitmix.com
) )
ASP.NET MVC Versus WebFormASP.NET MVC Versus WebForm
Web FormWeb Form Big Design Up Front (BDUF) methodologyBig Design Up Front (BDUF) methodology RAD and WinForm programming experienceRAD and WinForm programming experience
MVCMVC Not doing Big Design Up Front (BDUF) Not doing Big Design Up Front (BDUF) ““Close to the Metal” Programming ExperienceClose to the Metal” Programming Experience
ASP.NET MVC Versus WebFormASP.NET MVC Versus WebForm
Web FormsWeb Forms ViewState, Page Execution Lifecycle, Postback ViewState, Page Execution Lifecycle, Postback
ServicesServices Not Easy to TestNot Easy to Test Not Easy to Search (SEO)Not Easy to Search (SEO)
MVCMVC No ViewState, Page Execution Lifecycle, No ViewState, Page Execution Lifecycle,
Postback ServicesPostback Services Highly TestableHighly Testable Easy Search (SEO)Easy Search (SEO)
Consider MVC model, IfConsider MVC model, If
You want full control over HTMLYou want full control over HTML You want a framework that enforces You want a framework that enforces
separation of concernsseparation of concerns TDD/Unit Testing is priority for youTDD/Unit Testing is priority for you Control abstractions get in your way more Control abstractions get in your way more
than they helpthan they help You want easy integration with JavaScriptYou want easy integration with JavaScript
Consider WebForms model, IfConsider WebForms model, If
You want programming against the You want programming against the reusable control abstractions that reusable control abstractions that encapsulate UI and logicencapsulate UI and logic
You want RAD and Windows Form You want RAD and Windows Form development experiencedevelopment experience
You want to develop heavy data-driven Line You want to develop heavy data-driven Line of Business (LOB) Applications.of Business (LOB) Applications.
You must use MVC model, IfYou must use MVC model, If
You want adopt agile methodologyYou want adopt agile methodology You are a DDD/TDD believerYou are a DDD/TDD believer You want to develop public face internet You want to develop public face internet
applications and Web 2.0 applicationsapplications and Web 2.0 applications
ResourcesResources
ASP.NET MVC site - ASP.NET MVC site - http://http://as.net/mvcas.net/mvc
BlogsBlogs
Scott GuthrieScott Guthrie
http://http://weblogs.asp.net/scottguweblogs.asp.net/scottgu
Phill HaackPhill Haack
http://http://haacked.comhaacked.com
Stephen WaltherStephen Walther
http://http://weblogs.asp.net/stephenwaltherweblogs.asp.net/stephenwalther
Questions?Questions?
ThanksThanks
Shiju VargheseShiju Varghese
E-Mail : E-Mail : [email protected]@live.com
Blog : Blog : http://http://weblogs.asp.net/shijuvargheseweblogs.asp.net/shijuvarghese
Twitter : Twitter : http://http://twitter.com/shijucvtwitter.com/shijucv