asp.net mvc dev days09

Post on 14-Jul-2015

1.753 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

WUX201 WUX201 -- ASP.NET MVC ASP.NET MVC ASP.NET MVC RC1ASP.NET MVC RC1

Bruno TavaresBruno Tavares

Software Software EngineerEngineer @Sapo.pt@Sapo.pt

Objectives

• A session for developers

• Understating the MVC Pattern

• Understating the major concepts

• Scuba Diving on ASP.NET MVC

• Figure out scenarios where it can add value

Sometimes…

Editing/developing applications stuff makes me feel like I'm playing “Operation” with my daughter:

- It’s very tempting and easy to

blend concerns…blend concerns…

It’s hard to keep it simple any

Clean…

MVC Pattern

• MVC - Model/View/Controller

• MVC is a architectural pattern for Presentation Layer Model

• Isolates business logic from user interface

• Clean Separation of Concerns

• Highly maintainable applications

ControllerView

MVC Pattern

What is the Model?

• Responsible for data access, data persistence, data processing, business rules, etc.

ModelModel

Business EntitiesBusiness Entities

Processing DataProcessing Data

WorkflowWorkflow

• Agnostic of data presentation

• Responds to controller requests and notifies views that depend of some model

Access

Database

Webservice

MVC Pattern

What is the View?

• Responsible for presentation, look and feel, formatting, sorting, etc.

ViewView

Model

Display(HTML,etc.

• A Model can have multiple viewsFormat

UI Logic

Render

Display(HTML,

JSON, XML,

etc)

What is the Controller?

What is the Controller?

• Responsible for handling events, manipulate the model and select the view;

Controller

Event

Select

SelectView1

View2

Select View3

Select View

• Purpose is to receive a event and figure out what to do with it;

Model

Manipulate

Select View

Model Model

Handling event

What’s ASP.NET MVC RC1?

• Is the first Release Candidate (RC1)

• A new Web Project Type for ASP.NET

• Gives guidance for structuring web apps

• Convention over Configuration• Convention over Configuration

• Delivers RESTfull webapplications/websites

• Extensible and Pluggable – replace any component of the Framework

• Is fully testable (built with TDD in mind)

• More control over your <html/>

Where’s ASP.NET going?

• Is Microsoft’s ASP .NET going anywhere?

Where’s ASP.NET going?

• ASP.NET MVC is just an optionoption built over ASP.NET!

– System.Web;

– System.Web.MVC;

Choosing Between MVC and WebForms

ASP.NET Webforms:

• Web Forms is a well-understood technology

• Easy to get start

• Higher abstraction over HTML

• There are many applications where Web Forms work very well– Typical intranet database reporting app

– Corporate web applications that all the focus is functionality with constraints like time-to-market

– Web Application where presentation components have a lot of dependencies between witch others – vast marketplace of controls many of witch are extremely sophisticated

– Backoffices

Choosing Between MVC and WebForms

ASP.NET MVC:

• For those who like to get dirty over HTML

• Lower level or even no abstraction over HTML

• Multiple views over the same data (Model)

• For websites and web applications that you need to have full control over the output

• Use cases examples:– Blogs engines

– E-commerce store-front

– Vertical front-channels

Choosing Between MVC and WebForms

WebFormsWebForms•• Control ecosystemControl ecosystem

ASP.NETASP.NET•• ServicesServices

MVCMVC•• Do it yourselfDo it yourself

More control over detailsMore control over details

•• Control ecosystemControl ecosystem•• State manaState managementgement• Faster starting point -drag and drop

•• ServicesServices•• CachingCaching•• RoutingRouting•• LocalizationLocalization

•• Do it yourselfDo it yourself•• Separation of concernsSeparation of concerns•• Test Driven DevelopmentTest Driven Development•• Extensibility everywhereExtensibility everywhere

ReadyReady--toto--use building blocksuse building blocks

How it works in ASP.NET?

Request Request

HTTPHTTP

RoutingRoutingRouteRoute

ControllerControllerViewView

EngineEngine

ViewView ResponseResponse

demo demo -Project Creation-Routing

demo demo

How controllers and views works?

demos demos - Controllers and Views- ActionFilters and ResultActions- Build a ViewEngine

demos demos

#foo- foreach (var product in ViewData)

- if (product.Category.CategoryName != null)%h2=product.Category.CategoryName- break

%ul.productlist- foreach (var product in ViewData)

%li= Html.Image("/Content/Images/" + product.ProductID + ".jpg", product.ProductName).productdetail

=Html.ActionLink(product.ProductName, "Detail", new { ID=product.ProductID })%br

NHaml

=Html.ActionLink(product.ProductName, "Detail", new { ID=product.ProductID })%brPrice:=String.Format("{0:C2}", product.UnitPrice)

%span.editlink(=Html.ActionLink("Edit", "Edit", new { ID=product.ProductID }))

“.productdetail”

<div id=”productdetail”>

becomes

Spark

<ul class="productlist"><var styles='new[] {"odd", "even"}'/><li each="var product in ViewData.Model" class="${styles[productIndex%2]}">

<ProductImage style='"float:left;"'/><p><a href="/Products/Detail/${product.ProductID}">${product.ProductName}</a><br />Price: ${String.Format("{0:C2}", product.UnitPrice)}<span class="editlink">

(${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), "Edi(${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), "Edit")})</span></p><div style="clear:both;"></div>

</li></ul>

<li each="var product inViewData.Model"class="${styles[productIndex%2]}">

<li each="var product inViewData.Model"class="${styles[productIndex%2]}">

What's Next in MVC?

• Enterprise scaling features

– More control over session state

– Asynchronous controller actions

• Lambda-based helpers

Conclusion

• Fine-grained control over HTML

• It’s extensible and pluggable – add or change for what you like

• Clear separation of concerns

• Testability - support for Test-Driven Development

• ASP.NET MVC is an OPTION over ASP.NET webforms

Q&AQ&AQ&AQ&A

Software em versão completa para avaliaçãoSoftware em versão completa para avaliação

Suporte técnico 24x7 para incidentes

Acesso antecipado às versões beta

Microsoft Office

Software Assurance

formação gratuita ….e muito mais.

www.microsof t .com/por tuga l /msdn /subscr icoes

www.microso f t .com/ lear n ing /mcp /o f fe r s / secondshot

MSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN Flash

www.microsof t .com/por tuga l /msdn /msdnf lash

Participe nos próximos ciclos

Traga Amigos a assistir e …

www.microsof t .com/por tuga l /msdn /webcasts4share

Traga Amigos a assistir e …

…ganhe uma Xbox, trolleys e

livros

[BI] Resort

GASP

GetCertified

GetVirtual

Mundo Móvel

PocketPT

PontoNetPT

UC’ed

ScrumPT

ZoomIn

QuestionárioQuestionárioA sua opinião é importante!A sua opinião é importante!Complete o questionário de avaliação e Complete o questionário de avaliação e devolvadevolva--o no balcão da recepção.o no balcão da recepção.

Instituto Superior TécnicoInstituto Superior TécnicoInstituto Superior TécnicoInstituto Superior TécnicoCampus do TagusparkCampus do Taguspark

top related