Download - ASP.NET MVC 2

Transcript
Page 1: ASP.NET MVC 2

Jean-Claude TrachselSenior Consultant, Trivadis [email protected]

ASP.NET MVC 2

The good news

Page 2: ASP.NET MVC 2

Agenda

What is ASP.NET MVCFeatures of Version 2What about the «real life»?Summary

Page 3: ASP.NET MVC 2

What is ASP.NET MVC

A short introduction

Page 4: ASP.NET MVC 2

Framework based on Model-View-Controller PatternSeparation of Concerns

Framework is focusing on...Pure Web Development

Stateless, no ViewStateFull control over markup

TestabilityTDD, Unit Tests

MaintainabilityExtensibility and Flexibility Modern aspects like AOP, DI, IoC

What is ASP.NET MVC

Page 5: ASP.NET MVC 2

Positioning ASP.NET MVC

ASP.NET Web FormsASP.NET MVC

ASP.NET Framework

.NET Framework

Page 6: ASP.NET MVC 2

Visual Studio TemplateController and ViewUnit Test

Demo

Page 7: ASP.NET MVC 2

Features of Version 2

Areas, Validation, Typed UI Helpers, etc.

Page 8: ASP.NET MVC 2

Goals of the DevTeam for Version 2

More Productivity

More Security

More Performance

More Extensibility

More Happiness

What do we get?

Page 9: ASP.NET MVC 2

What we will look at

AreasValidationTyped UI HelpersUI Helper TemplatesAsync Controllers

Page 10: ASP.NET MVC 2

Areas

Single Project and Multi Project Areas

Page 11: ASP.NET MVC 2

Enterprise ready with Areas

Structure your Solution with...

Single Project Area

Multi Project Area

Easy re-use of Code

Areas – what for?

Page 12: ASP.NET MVC 2

Single Project Area

Folder Structur

Route Class

Inherits from AreaRegistration

Defines the route to the Controller

Global.asax

Register the area routes

Areas – what’s needed?

Page 13: ASP.NET MVC 2

Single Project Areas

Demo

Page 14: ASP.NET MVC 2

Validation

Data Annotations Attributes

Page 15: ASP.NET MVC 2

Data Validation with DataAnnotations Attributes

Introduced with .NET 3.5 SP 1

Benefits of DataAnnotations Attributes

Set in one central place, on the model

Used by different Technologies

Used in ASP.NET Dynamic Data

Used in WCF RIA Services

ASP.NET MVC Validation

Page 16: ASP.NET MVC 2

Use of DataAnnotations

Set Attributes on the Model

[MetadataType(typeof(ProductMetadata))]public partial class Product{}

public class ProductMetadata{ [Required] public string Name { get; set; } }

Page 17: ASP.NET MVC 2

Attributes that are available

Required

Range

RegularExpression

StringLength

CustomValidation

Build your own

DataAnnotations

Page 18: ASP.NET MVC 2

Server Site Validation

ModelBinder Class

Client Site Validation

jQuery Validation Library

Validation in ASP.NET MVC

Page 19: ASP.NET MVC 2

Validation with DataAnnotation AttributesServer- and Client Site

Demo

Page 20: ASP.NET MVC 2

Typed UI Helpers

...and the UI Helper Templates

Page 21: ASP.NET MVC 2

HtmlHelper ExtensionsASP.NET MVC 1

ASP.NET MVC 2

Typed UI Helpers

<%=Html.TextBox(„ProductID“,Model.ProductID)%><%=Html.Label(„Name“,Model.Name)%><%=Html.RadioButton(„Avail“,Model.Available)%>

<%=Html.DisplayFor(p => p.ProductID)%><%=Html.Ed itorFor(p => p.ProductID)%>

Page 22: ASP.NET MVC 2

Benefits are...

Intellisense

Compile Time Support

Type based rendering

Support for standard and complex types

Typed UI Helpers

Page 23: ASP.NET MVC 2

Extend the Typed UI Helper Methods

Define the Rendering via UserControls

Supports standard and complex types

Used by...

Name Convention

UI Helper Method Parameter

ViewModel Attributes

UI Helper Templates

Page 24: ASP.NET MVC 2

Typed UI HelpersUI Helper Template for DateTime

Demo

Page 25: ASP.NET MVC 2

Async Controllers

Be smart, be fast

Page 26: ASP.NET MVC 2

Use of Async Controllerpublic class HomeController : AsyncController{ public void NAMEAsync() { AsyncManager.OutstandingOperations.Increment(3); // Do all Tasks asynchronouse }

public ActionResult NAMECompleted(object params) { // Do final work return View("NAME"); }}

Page 27: ASP.NET MVC 2

Async Controller is a Server Side Pipeline

For Async Clinet/Server Requests use AJAX

Do Multiple Tasks at once

Get data from different stores at the same time

Prevent Blocking of the Webserver

Worker Threads are not blocked

No Thread starvation

Async Controllers

Page 28: ASP.NET MVC 2

Use synchronouse pipelines

Operations are simple or short-running

Simplicity is important

Use asynchronouse pipelines

Operations are network-bound or I/O-bound

Parallelism is important

Provide a mechanism to cancel long-running request

Async Controllers

Page 29: ASP.NET MVC 2

Async Controllers

Demo

Page 30: ASP.NET MVC 2

What about «real life»?

Experience from current projects

Page 31: ASP.NET MVC 2

It’s a Paradigm Shift

Can be hard for MS Win-/WebForms Developers

Easier for PHP, Java, etc. Developers

It’s a lot of Client Side Programming

New Know-How is needed

Learn ASP.NET MVC

Page 32: ASP.NET MVC 2

Convention over ConfigurationEasy to understand

New Team MembersMaintenance

More Unit TestsBetter QualityLess Bugfixing

Better Reusability

Productivity – the good side

Page 33: ASP.NET MVC 2

No reuse of existing...

Concepts

Frameworks

Controls

Loss of Functionality

(GUI)Libraries

Productivity – the down side

Page 34: ASP.NET MVC 2

Summary & Resources

3, 2, 1, go

Page 35: ASP.NET MVC 2

New Web Development Paradigm perfect for...TDD, Large Projects and Teams

Many new Features to gain...Productivity and happiness

Use ASP.NET MVCWhen ever you can

Use ASP.NET WebFormsNeed to use existing Frameworks, Libs or ControlsNo time to establish needed Know-How

Summary

Page 36: ASP.NET MVC 2

Productivity Tasked based helpersValidation Improvements

Ajax Multiple Partial UpdatesClient Templates Support

ArchitectureDependency Injection at all levels MEF Controller (Managed Extensibility Framework)

Performance Improved Caching More Control over Session

ASP.NET MVC 3

Page 37: ASP.NET MVC 2

Websiteshttp://www.asp.net/mvchttp://www.codeplex.com/aspnet

Blogshttp://www.haacked.com/http://weblogs.asp.net/scottguhttp://www.hanselman.comhttp://stephenwalther.com/blog

Resources

Page 38: ASP.NET MVC 2

Thank you for your Attention!For more Information please contact

Jean-Claude TrachselSenior Consultant

[email protected] 4000 900

Trivadis AGEuropastrasse 58152 Glattbrugg

Page 39: ASP.NET MVC 2

SharePoint 2010SQL Server 2008 R(2)efreshedBusiness Intelligence mit Microsoft in 2010

Trainings Voucher für 1 Schulungstag (Wert CHF 870.-)

Talent Scout

Herausfordernde, attraktive Jobs warten Melden Sie sich!

Besuchen Sie unseren Stand

Trivadis Innovation Partnership Programm (TIPP)Gemeinsame Innovations-Projekte

Page 40: ASP.NET MVC 2