jean-claude trachsel senior consultant trivadis ag building a website with asp.net mvc

30
Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Upload: elmer-franklin

Post on 03-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Jean-Claude TrachselSenior ConsultantTrivadis AG

Building a Website withASP.NET MVC

Page 2: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

My ProfileDon’t hesitate to contact me

Page 3: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

IT SOLUTIONS, SERVICES, & PRODUCTS

TECHNOLOGIESMicrosoft, Oracle, IBM, Open Source

Integration, Application Performance Management, Security

TrainingManaged Services

InfrastructureEngineering

Application Development

Enterprise Content Management

BUSINESS INTEGRATION SERVICES

ITdepartmen

ts

Businessdepartmen

ts

CUSTOMER

Business Intelligence

Trivadis solutions portfolio and competences

Page 4: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Hamburg

Düsseldorf

Frankfurt

Stuttgart

MunichFreiburg

Vienna

Basel

Bern

Zurich

Lausanne~370 employees

~170 employees

~20 employees

Trivadis facts & figures11 Trivadis locations with more than 550 employees

Financially independent and sustainably profitable

Key figures 2010

Revenue CHF 101 / EUR 73 mio.

Services for more than 700 clients in over 1‘800 projects

Over 170 Service Level Agreements

More than 5'000 training participants

Research and development budget:

CHF 5.0 / EUR 3.6 mio.

Page 5: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Agenda

What is ASP.NET MVCBuilding a WebsiteFeatures we need to know

IntroductionLevel 100

Page 6: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

What is ASP.NET MVC

Web Development FrameworkBased on the ASP.NET FrameworkBased on the MVC Design Pattern

Acronym for Model ● View ● ControllerSeparation of concerns

Page 7: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Web Development StackMicrosoft’s HTML Technologies

ASP.NET Web Forms ASP.NET MVC

ASP.NET Framework

.NET Framework

Page 8: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Technologie FocusASP.NET

WebForms

Make Web Development fast and easy

Hide Web Specifica

WinForms similar Programming Model

Statefull, event driven, many rich controls

ASP.NET MVC

Full Control Web Development

Great Testability, Maintainability and Extensibility

Stateless, trendy, separation of concerns,perfect ajax integration

Page 9: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Agenda

What is ASP.NET MVCBuilding a WebsiteFeatures we need to know

ModelControllerViewTest

Page 10: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

IntroductionStep one

Build a website in 5 stepsAdventureWorks DBCRUD Functionality for Vendor table

Setup the Solution

Define the Model

Build the ControllerBuild some

Views

Build a Unit Test

Page 11: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

DemoStep one

Setup the Solution

Define the Model

Build the ControllerBuild some

Views

Build a Unit Test

Page 12: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Model FundamentalsStep two

ModelBusiness Logic LayerData Access Layer

ArchitectureRepository PatternServices Layer

This is not ASP.NET MVC specific

SolutionModelControll

erViewsUnit Test

Page 13: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Demo ArchitectureMVCProject

Controller

Controller

Controller

ViewViewView

Mod

el

DataProject Entity Framework

ModelDataAnnotations

ServicesProject

IEn…on<T> GetItems();T GetItem(int id);void Save();

IRepository<T> IEnumeration<T>

GetItems();T GetItem(int id);void Save();

VendorRepository

SolutionModelControll

erViewsUnit Test

Page 14: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

DemoStep two

Setup the Solution

Define the Model

Build the ControllerBuild some

Views

Build a Unit Test

Page 15: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Controller FundamentalsStep threeController

Class in C# (VB)Handles all interactions and requests

Controller base classProvides many helper methods

Action Return ValuesFor testing purpose

SolutionModelControll

erViewsUnit Test

Page 16: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

DemoStep three

Setup the Solution

Define the Model

Build the ControllerBuild some

Views

Build a Unit Test

Page 17: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

View FundamentalsStep four

ViewAspx or Razor (.cshtml) FileNo Code Behind File

ControlsNo Server Controls (no ViewState)Pure HTML

CodePresentation Logic in C# (VB) or JavaScriptHtml Helper class

SolutionModelControll

erViewsUnit Test

Page 18: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

DemoStep four

Setup the Solution

Define the Model

Build the ControllerBuild some

Views

Build a Unit Test

Page 19: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Unit Test FundamentalsStep fiveTest Controller Logic

Seperate Test ProjectsViewsModels

Usefull toolsDependency Injection (DI)Mock Framework

SolutionModelControll

erViewsUnit Test

Page 20: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

DemoStep five

Setup the Solution

Define the Model

Build the ControllerBuild some

Views

Build a Unit Test

Page 21: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Agenda

What is ASP.NET MVCBuilding a WebsiteFeatures we need to know

ValidationFilterRazor

Page 22: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Validation

Supports DataAnnotations FeaturesAttributes on the modelGenerates Client- and Server Code

.NET 4 DA-Features Support (Version 3 Feature)

IsValid overloads in the ValidationAttributeIValidatableObject Interface

Remote Validation Attribute (Version 3 Feature)

Defines Controller and Action for jQuery validation

Page 23: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Filters

Aspect Oriented Programming (AOP) Framework

Integrated in ASP.NET MVCStandard Filters

[HandleError], [Authorize], [OutputCache]Base class for your own filter

Global Filters (Version 3 Feature)Conditional filters thru IFilterProvider

Page 24: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

RazorThe new View Engine

Compact, Expressive and FluidEasy to learnIs not a new languageWorks with any Text EditorVisual Studio provides Intellisense and syntax highlighting

Page 25: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Advantages of RazorThe new View Engine

1 character instead of 5 for code blocksRazor: @ (no closing tag needed)Parser has semantic knowledge of C# / VBAspx: <%: %>

Coding is fast, fluid and fun

Page 26: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

“Hello world” sample<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master“ Inherits="System.Web.Mvc.ViewPage<Product>" %><asp:Content ID="Title" ContentPlaceHolderID="TitleContent“ runat="server"> Razor Demo</asp:Content><asp:Content ID="Contnt" ContentPlaceHolderID="MainContent" runat="server"> <h2>Razor Demo</h2> Hello World, we got Number 1: <%: Model.Number1 %>

and Number 2: <%: Model.Number2 %>.</asp:Content>@model Trivadis.Models.Product@{View.Title = "Razor Demo";}<h2>Razor Demo</h2>Hello World, we got Number 1: @Model.Number1 and Number 2: @Model.Number2.

Razor

aspx

Page 27: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

ResourcesStart today with ASP.NET MVC and Razor

http://www.asp.net/mvchttp://haacked.com/http://stephenwalther.com/blog/http://weblogs.asp.net/scottgu/http://blog.trivadis.com/blogs/

Page 28: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Trivadis TechDays11 Wettbewerb

Gutschein

für einen

kostenlose

n

Trivadis

Training

Tag

1. Preis

2. Preis

3. Preis

Mehr Infos am Trivadis Stand

Mit Signaturvon Thomas Huber

Page 29: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

Q&A

Page 30: Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC

© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after

the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.