asp.net mvc dev days09

31

Upload: bruno-matos-tavares

Post on 14-Jul-2015

1.753 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Asp.Net Mvc Dev Days09
Page 2: Asp.Net Mvc Dev Days09

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

Bruno TavaresBruno Tavares

Software Software EngineerEngineer @[email protected]

Page 3: Asp.Net Mvc Dev Days09

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

Page 4: Asp.Net Mvc Dev Days09

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…

Page 5: Asp.Net Mvc Dev Days09

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

Page 6: Asp.Net Mvc Dev Days09

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

Page 7: Asp.Net Mvc Dev Days09

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)

Page 8: Asp.Net Mvc Dev Days09

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

Page 9: Asp.Net Mvc Dev Days09

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/>

Page 10: Asp.Net Mvc Dev Days09

Where’s ASP.NET going?

• Is Microsoft’s ASP .NET going anywhere?

Page 11: Asp.Net Mvc Dev Days09

Where’s ASP.NET going?

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

– System.Web;

– System.Web.MVC;

Page 12: Asp.Net Mvc Dev Days09

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

Page 13: Asp.Net Mvc Dev Days09

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

Page 14: Asp.Net Mvc Dev Days09

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

Page 15: Asp.Net Mvc Dev Days09

How it works in ASP.NET?

Request Request

HTTPHTTP

RoutingRoutingRouteRoute

ControllerControllerViewView

EngineEngine

ViewView ResponseResponse

Page 16: Asp.Net Mvc Dev Days09

demo demo -Project Creation-Routing

demo demo

Page 17: Asp.Net Mvc Dev Days09

How controllers and views works?

Page 18: Asp.Net Mvc Dev Days09

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

demos demos

Page 19: Asp.Net Mvc Dev Days09

#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

Page 20: Asp.Net Mvc Dev Days09

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]}">

Page 21: Asp.Net Mvc Dev Days09

What's Next in MVC?

• Enterprise scaling features

– More control over session state

– Asynchronous controller actions

• Lambda-based helpers

Page 22: Asp.Net Mvc Dev Days09

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

Page 23: Asp.Net Mvc Dev Days09
Page 24: Asp.Net Mvc Dev Days09

Q&AQ&AQ&AQ&A

Page 25: Asp.Net Mvc Dev Days09

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

Page 26: Asp.Net Mvc Dev Days09

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

Page 27: Asp.Net Mvc Dev Days09

MSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN FlashMSDN Flash

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

Page 28: Asp.Net Mvc Dev Days09

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

Page 29: Asp.Net Mvc Dev Days09

[BI] Resort

GASP

GetCertified

GetVirtual

Mundo Móvel

PocketPT

PontoNetPT

UC’ed

ScrumPT

ZoomIn

Page 30: Asp.Net Mvc Dev Days09

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.

Page 31: Asp.Net Mvc Dev Days09

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