Introduction to ASP.NET MVC


Published on

Introduction to ASP.NET MVC by Mayank Srivastava @ MPS Partners.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Introduction to ASP.NET MVC

  1. 1. © 2009 SPR Companies. All rights reserved. MPS Partners An SPR Company Brown Bag Lunch Series: 10/06/2010 An Introduction To ASP.NET MVC by Mayank Srivastava
  2. 2. Table of Contents The Framework Frequently Bought Together The Pattern The Product
  3. 3. So what is MVC pattern? Image from Model-View-Controller is an architectural pattern that isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns).
  4. 4. Basics ASP.NET Web Forms + MVC Pattern = ASP.NET MVC ASP.NET + MVC Pattern = ASP.NET MVC ASP.NET == ASP.NET Web Forms
  5. 5. ASP.NET - The Song Remains The Same
  6. 6. Web Forms Request (*.aspx) PageHandlerFactory Responsible for page processing engine Create a server form Execute Page life cycle Load View state / Control state Server Form / Page Response (Browser understandable content) Inheriting System.Web.UI.Page does the trick.
  7. 7. So what is MVC pattern? Model • Domain-specific representation of data • Business logic • Storage layer is an implementation detail
  8. 8. So what is MVC pattern? View • Presents data to the user • Read-only views as well as forms • Minimal display-only logic
  9. 9. So what is MVC pattern? Controller • Responds to requests • Connects models to view • Invokes model code as appropriate
  10. 10. MVC based ASP.NET framework Request (URL) Controller Response (Browser understandable content) Model View -> Get the model (if needed) -> Bind the model to the view (if needed) ->Render the view Viewsknowhowtopresentmodels Other related frameworks -
  11. 11. So what changed… No Page life cycle • No Server page, no server controls, only Views! • Web is state ‘LESS’ environment. • An asynchronous call should be an asynchronous call. No View state • Again, web is state ‘LESS’ environment. • In hindsight, for the stateless web - state should be Model’s responsibility, not View’s overhead. No Postback • Only Http verbs – Get, Post, Put, Delete.
  12. 12. Over to Visual Studio
  13. 13. A Quick comparison • • Asynchronous when you need Synchronous when you don’t Web Forms MVC Try reload / paging on Telerik’s WebForm’s Grid and compare the performance against Telerik’s MVC grid.
  14. 14. Page 14 Some more Super Hero talk
  15. 15. Page 15 Routing It’s all about Routes, not file path.  Application/Controller/Action/Parameter  Or whatever you want  Search Engine Optimization  Imagine possibilities –  Windows Workflow Foundation  RSS feeds  Window communication foundation  The Browse / Ajaxify Pretty much anything!
  16. 16. Over to Visual Studio
  17. 17. Page 17 Deeper dive Oh and by the way – ASP.NET MVC, aka System.Web.Mvc, is Open Source Check out the code on :-
  18. 18. Page 18 Frequently bought together Customers Who Bought This Item Also Bought • n-Tier application architecture (Separation of concern). • IoC – Inversion of control (Dependency injection). • TDD – Test Driven Development. 18
  19. 19. Page 19 Separation of Concern What concern? Why are you concerned? My application works fine! Remember Models?
  20. 20. Page 20 Separation of concern Model Nothing but POCO Domain-specific representation of data Domain Models Business logic Business Layer Storage layer is an implementation detail Data Access Layer
  21. 21. Page 21 Separation of concern Most Common (rather default) Design Patterns • Services Based for extendibility • Repositories for Data Access Layer
  22. 22. Page 22 DI & IoC Dependency injection (Image - • Static kernel based container • Control over scope (singleton, Request) • Popular frameworks – Unity (Enterprise Library), StructureMap, Ninject, Castle Windsor, Spring.NET…
  23. 23. Page 23 Inversion of Control Database Web Client Services Repositories ICacheService ICacheRepository WP7 App Facebook Canvas Use HttpCacheService : ICacheService & SQLCacheRepository : ICacheRepository Use WPCacheService : ICacheService & LocalFileCacheRepository : ICacheRepository Use WPCacheService : ICacheService & LocalFileCacheRepository : ICacheRepository How should I handle your cache needs?
  24. 24. Page 24 Test Driven Development Why is it the big breakthrough? Is it testable? – No… (at least not easily) Is it testable? – Yes! var product = new ProductController(); var result = product.List();
  25. 25. Page 25 Why MVC • App Driven Development • Industry moving towards Usability • It’s all about user experience Usability = (Functionality ^ Look) * Feel;
  26. 26. Page 26 Future? Is this the end of Web Forms? Now that MVC is here. No! That’s ridicules! (as on
  27. 27. Page 27 Future? Flashback Is this the end of VB? Now that C# is here. No! That’s ridicules! However VB can’t be used on some cool stuff like Window Phone, the .NET Micro Framework err…I mean VB is equally good.
  28. 28. Page 28 Resources Learning Resources: Prominent bloggers: Scott Guthrie - Scott Hanselman - Phil Haak - Rob Conery - Jon Galloway - Stevens Anderson - Brad Wilson - Also: Me :) -
  29. 29. Page 29 Questions