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

Download Report

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

Building a Website with
ASP.NET MVC
Jean-Claude Trachsel
Senior Consultant
Trivadis AG
My Profile
Trivadis solutions portfolio and competences
CUSTOMER
Business
departments
IT
departments
BUSINESS INTEGRATION SERVICES
IT SOLUTIONS, SERVICES, & PRODUCTS
Business Intelligence
Enterprise Content
Management
Infrastructure
Engineering
Application
Development
Training
Managed Services
Integration, Application Performance
Management, Security
TECHNOLOGIES
Microsoft, Oracle, IBM, Open Source
Trivadis facts & figures
11 Trivadis locations with more than 550
employees
Hamburg
Financially independent and sustainably
profitable
Key figures 2010
~170 employees
Düsseldorf
Revenue CHF 101 / EUR 73 mio.
Frankfurt
Services for more than 700 clients in
over 1‘800 projects
Stuttgart
Vienna
Freiburg
Basel
Bern
Lausanne
Zurich
~370 employees
Munich
~20 employees
Over 170 Service Level Agreements
More than 5'000 training participants
Research and development budget:
CHF 5.0 / EUR 3.6 mio.
Agenda
What is ASP.NET MVC
Building a Website
Features we need to know
What is ASP.NET MVC
Web Development Framework
Based on the ASP.NET Framework
Based on the MVC Design Pattern
Acronym for Model ● View ● Controller
Separation of concerns
Web Development Stack
ASP.NET Web Forms
ASP.NET MVC
ASP.NET Framework
.NET Framework
Technologie Focus
ASP.NET WebForms
ASP.NET MVC
Make Web Development
fast and easy
Full Control Web
Development
Hide Web Specifica
Great Testability,
Maintainability and
Extensibility
WinForms similar
Programming Model
 Statefull, event driven,
many rich controls
 Stateless, trendy,
separation of concerns,
perfect ajax integration
Agenda
What is ASP.NET MVC
Building a Website
Features we need to know
Introduction
Build a website in 5 steps
AdventureWorks DB
CRUD Functionality for
Vendor table
Demo
Setup the Solution
Model Fundamentals
Model
Business Logic Layer
Data Access Layer
Architecture
Repository Pattern
Services Layer
This is not ASP.NET MVC specific
Model
MVC
Project
Services
Project
Data
Project
Controller
Controller
Controller
View
View
View
IRepository<T>
VendorRepository
IEn…on<T> GetItems();
T GetItem(int id);
void Save();
IEnumeration<T> GetItems();
T GetItem(int id);
void Save();
Entity Framework Model DataAnnotations
Model
Demo Architecture
Model
Demo
Define the Model
Controller Fundamentals
Controller
Class in C# (VB)
Handles all interactions and requests
Controller base class
Provides many helper methods
Action Return Values
For testing purpose
Controller
Demo
Build the Controller
View Fundamentals
View
Aspx or Razor (.cshtml) File
No Code Behind File
Controls
No Server Controls (no ViewState)
Pure HTML
Code
Presentation Logic in C# (VB) or JavaScript
Html Helper class
Views
Demo
Build some Views
Unit Test Fundamentals
Test Controller Logic
Seperate Test Projects
Views
Models
Usefull tools
Dependency Injection (DI)
Mock Framework
Unit Test
Demo
Build a Unit Test
Agenda
What is ASP.NET MVC
Building a Website
Features we need to know
Validation
Supports DataAnnotations Features
Attributes on the model
Generates Client- and Server Code
.NET 4 DA-Features Support (Version 3 Feature)
IsValid overloads in the ValidationAttribute
IValidatableObject Interface
Remote Validation Attribute (Version 3 Feature)
Defines Controller and Action for jQuery validation
Filters
Aspect Oriented Programming (AOP) Framework
Integrated in ASP.NET MVC
Standard Filters
[HandleError], [Authorize], [OutputCache]
Base class for your own filter
Global Filters (Version 3 Feature)
Conditional filters thru IFilterProvider
Razor
Compact, Expressive and Fluid
Easy to learn
Is not a new language
Works with any Text Editor
Visual Studio provides
Intellisense and syntax highlighting
Advantages of Razor
1 character instead of 5 for code blocks
Razor: @ (no closing tag needed)
Parser has semantic knowledge of C# / VB
Aspx: <%: %>
Coding is fast, fluid and fun 
“Hello world” sample
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master“
aspx
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
Razor
@{View.Title = "Razor Demo";}
<h2>Razor Demo</h2>
Hello World, we got Number 1: @Model.Number1 and Number 2: @Model.Number2.
Resources
http://www.asp.net/mvc
http://haacked.com/
http://stephenwalther.com/blog/
http://weblogs.asp.net/scottgu/
http://blog.trivadis.com/blogs/
Trivadis TechDays11 Wettbewerb
© 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.