• Save
ASP.NET MVC Presentation
Upcoming SlideShare
Loading in...5
×
 

ASP.NET MVC Presentation

on

  • 4,821 views

My ASP.NET MVC presentation at the San Diego .NET User Group

My ASP.NET MVC presentation at the San Diego .NET User Group

Statistics

Views

Total Views
4,821
Views on SlideShare
4,814
Embed Views
7

Actions

Likes
1
Downloads
0
Comments
0

3 Embeds 7

http://www.slideshare.net 4
http://www.linkedin.com 2
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Use Repository Pattern Separate the Model layer from Control layerMVC is in presentation layer, model is in persistence layerDon’t let your UI talk to business model directlyUse orm, orm is not for only if I change the db later…
  • Use automapper, silverlight and wpf has binding support , and mvvm support

ASP.NET MVC Presentation ASP.NET MVC Presentation Presentation Transcript

  • ASP.NET MVC
    VolkanUzun
  • Web Developer at California State University, San Bernardino
    MS. Computer Science, MCP, and MCTS
    Interest Areas: TDD, Web Programming, Secure Coding
    User group maniac, visiting many user groups in a month
    Blog: http://www.msnetprogrammer.net/blog,
    Email: volkan@iedotnetug.org
    Twitter: http://www.twitter.com/volkanuzun
    About Me
  • Classic ASP (Another Slow Page!?)
    .NET Framework (Hurraay!!)
    ASP.NET v1.0 (No more slow pages)
    ASP.NET v1.1
    ASP.NET v2.0
    ASP.NET Ajax
    ASP.NET 3.5
    Silverlight ?!?!
    ASP.NET MVC
    ASP.NET WebForms 4.0
    ….
    MS Web Developer History
  • Easy to learn but?
    Maintenance?
    Test?
    Debugging?
    Complexity?
    What was wrong with ASP?
  • Desktop like programming paradigm
    Lot’s of out ofbox controls
    No more spaghetti code?
    ASP.NET Web Forms
  • ViewState (supposed to help you but?)
    DRY
    Can’t control HTML(Power is nothing without control)
    Best Practices?
    Separation of Concerns? (I don’t have any concern)
    What is wrong with ASP.NET WebForms?
  • New Patterns
  • MVC
    Different people reading about MVC in different places take different ideas from it and describe these as “MVC”.
    Martin Fowler, GUI Architectures Essay (July 2006)
  • Model–View–Controller (MVC) is an architectural pattern 
    Formulated in 1979 by TrygveMikkjel Heyerdahl Reenskaug
    The model is the domain-specific representation of the data upon which the application operates
    The controller receives input and initiates a response by making calls on model objects.
    The view renders the model into a form suitable for interaction
    Wikipedia: MVC
    • A new web project type built on top of ASP.NET.
    • NOT replacing ASP.NET Web Forms.
    • Giving you more control over html.
    • An easier to test framework.
    • Another option to web development.
    • Open source.
    • Convention over configuration.
    ASP.NET MVC
  • No View State, No Postback
    Very flexible, pluggable.
    Very clean URLs, rest friendly urls.
    Supports ASP.NET Providers: Membership Provider, Role Provider, Session, Cache etc…
    Open Source.
    Community Support.
    Supports Separation of Concerns.
    Plays well with others
    Why is it good?
  • Complete control over html!!
    No View State, No Postback!!
    Paradigm change.
    Few components .
    No formal validation support.
    Any Disadvantage?
  • WebForms are dead?
    MVC does not have as much support as WebForms?
    MVC guarantees better coding?
    A project is either MVC or WebForms?
    MVC is faster than WebForms?
    True / False
  • Browser requests /Products/List
    Route is selected
    Controller is activated (Products)
    Controller executes the action method (List)
    Action talks to Model, prepares the ViewData
    Action renders View
    But what is it?
  • Located in Controllers folder, You can change it
    derived from Controller base class
    The class name should be controller name + “Controller”
    Action Methods does the work
    Delete AccountController
    Move Controller’s to a separate project
    Controller
  • The ambiguous part of ASP.NET MVC
    M is the only part of MVC that is not implemented in ASP.NET MVC
    View Model: How your data looks on the page, flat data
    Domain Model: How your business data is, hierarchical data
    Any ORM is fine
    MODEL
  • Just renders the page, no biz logic!!!
    No ViewState, no server controls
    NO Codebehind, pls DON’T
    Default ViewEngine is WebForms
    Communicates with Controller with ViewData Dictionary
    Strongly Typed View
    VIEW
  • FILE => NEW…
    Project Structure
  • Separate Domain Model and View Model
    Use an ORM
    Use Repository Pattern
    Domain Model should only validate domain rules
    Presentation layer should NOT care about persistence layer
    Best Practices on Model
  • FALSE
    ViewModel == DomainModel
    The most annoying part of Presentation Model is the synchronization between Presentation Model and view…
    Martin Fowler, GUI Architectures Essay, July 2004
  • Music Store App
    Display Albums
    Display Customers
    Refactor the Model
    Use AutoMapper
    DEMO
  • No Business Logic
    No Concrete Dependencies
    Small Action Methods
    Don’t mix HttpVerbs
    Avoid magic strings
    Use controller as a traffic flow manager
    Unit test your expectations
    All the public methods are web accessible
    Use OutputCache
    Best Practices on Controller
  • Define Views in an enum:return View(viewNames.Index);
    Even Better use T4MVC
    View.Model
    MVCContrib for RedirectToAction:return RedirectToAction<HomeController>(c=>c.Index)
    Removing Magics in Controller
  • Refactor View Names and Links with T4MVC
    Cache the output
    Write simple unit test
    DEMO
  • Dependency Injection
    private IBookRepositorybookRepository;public HomeController(){bookRepository = new BookRepository();}
    • What if BookRepository has dependencies?
    • Is it HomeContoller’s job to satisfy dependencies?
    • Why does Home Controller have to know about BookRepository()?
    • What if HomeController needs initialization param in the constructor?
  • private IBookRepositorybookRepository;public HomeController(IBookRepository repo){bookRepository = repo;}
    But who calls the controller with a parameterized constructor?
    NOT MVC Framework, at least not the default ControllerFactory
    Better Injection
  • Extend ControllerFactory
    Use one of the IOC frameworks:StructureMap, Ninject, Windsor etc…
    Even Better Injection
  • CastleWindsorController Factory
    DEMO
  • No Magic String (use T4MVC)
    Change ../ paths
    Strongly Typed View
    RenderPartial
    HtmlHelpers
    Use HTML if you can
    If there is an “If” , time to check HtmlHelpers
    Encode input string
    Best Practices On View
  • RenderPartial Customer
    RefactorStyleSheet
    DEMO
  • Separate Controllers
    Use IoC
    No Business Logic in Controllers
    No Magic Strings in any component
    Use HTML Helpers
    DRY
    Test
    Strongly Types Views
    List of Practices
  • Client side validation with JQuery
    Templating
    Strongly typed helpers
    Areas Support
    Async Controller Actions
    New Things With MVC 2
  • Thanks to Jonas Follesø (http://jonas.follesoe.no)
    Thank you