introduction to asp.net 5 and mvc 6 - meetupfiles.meetup.com/16095872/aspnet5mvc6.pdf ·...

69
Introduction to ASP.NET 5 and MVC 6

Upload: others

Post on 31-Aug-2019

25 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Introduction to ASP.NET 5 and MVC 6

Page 2: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Ovais Mehboob Ahmed Khan

MICROSOFT MVP Visual Studio and Development Technologies

DZone MVB

@ovaismehboobReach me at:

[email protected]

Page 3: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

History of ASP.NET

• 2002 – ASP.NET

• 2008 – ASP.NET MVC

• 2010 – ASP.NET Web Pages

• 2012 – ASP.NET Web API, Signal R

• 2015 – ASP.NET 5

Page 4: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

What’s come in .NET 2015

Page 5: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys
Page 6: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys
Page 7: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys
Page 8: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

.NET Core

Page 9: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

.NET Core

Page 10: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

.NET Core •

Page 11: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

.NET Core Major Components• Two Major Components

• Core CLR • Built on the same codebase as the .NET Framework CLR.

• Includes the same GC and JIT (RyuJIT)

• Does not include features like Application Domains or Code Access Security.

• The runtime is delivered on NuGet (Microsoft.CoreCLR package)

• .NET Core Foundation Libraries (CoreFX)• Are the same code as the .NET Framework class libraries but does not contain

dependencies so have a smaller footprint.

• Available on NuGet (System.* package)

Page 12: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Core CLR

Page 13: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys
Page 14: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

ASP.NET Transition

Page 15: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

ASP.NET 5 and the Modern Web

Page 16: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Modern Web – Agility

Page 17: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Modern Web - Fast

Page 18: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Modern Web – Cloud

Page 19: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Modern Web – Cross Platform

Page 20: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

DemoExplore VS 2015 project templates

Create ASP.NET Web Application

Discuss ASP.NET 5 Environment Files

Page 21: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Command Line Tools

- DNX (.NET Execution)- New execution environment of .NET- DNX bootstraps and runs your application- Not the CLR only, contains CoreFX as well- Install using DNVM

- DNVM (.NET Version Manager)- Set of command line utilities to update and configure which .NET Runtime to use- Downloadable from aspnet/home GitHub repository

- DNU (.NET Utility)- .NET Utility used to perform tasks like building, installing packages etc

Page 22: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

DNX

Page 23: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Getting DNX

Page 24: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

DNX

Page 25: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

DNX

Page 26: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

DNX

Page 27: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Running DNX

Page 28: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

DNU

Page 29: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

ASP.NET 5

Page 30: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Servers

• IIS and WebListener is for Windows only

• Kestrel is designed to run Cross Platform

Page 31: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Windows based Servers

• IIS and IIS Express• Hosting ASP.NET 5 on IIS bypasses the legacy System.Web infrastructure and

load pipeline defined in Startup.cs

• WebListener• Windows-only server that allows ASP.NET to be hosted outside IIS,

• Runs directly on Http.Sys kernel driver of windows

• It provides same features interface as IIS

• You can think it as a library version of IIS

Page 32: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Cross Platform Server

• Kestrel• Web server based on libuv

• Libuv – cross platform asynchronous I/O library

• Kestrel is open source

• View on github

• https://github.com/aspnet/KestrelHttpServer

Page 33: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

ASP.NET 5 invoked

Page 34: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Pipeline primitives

Page 35: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Dependency Injection

Page 36: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Registering Dependencies

Page 37: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Dependency Resolution

ASP.NET 5 depends on many packages

How the CLR Load the assemblies?

Two rules for loading Dependencies

- Nearest wins

- Cousin dependencies

Page 38: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Application using Nearest Wins

- Nearest-Wins allows a package/application to override any particular version of a package in its dependency tree by directly depending on the version it wants.

Page 39: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Package using Nearest Wins

Page 40: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Configuration

Page 41: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Configuration Example

Page 42: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys
Page 43: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Packaging & Publishing

Page 44: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

MVC 6

Page 45: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Packaging

Page 46: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Middleware

Page 47: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Routing

Page 48: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Controller

Page 49: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Attribute Routing

Page 50: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Combining Routing Parameters

Page 51: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Route Parameters

Page 52: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

HTTP Based Routes

Page 53: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Areas

Page 54: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

POCO Controllers

Page 55: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Dependency Injection

Page 56: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Model Binding Changes

Page 57: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Razor Directives

Page 58: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

@inject

Page 59: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Tag Helpers

Page 60: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Tag Helpers

Page 61: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Tag Helper Implementation

Page 62: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

MVC Tag Helpers

Page 63: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Validation Tag Helpers

Page 64: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Publishing

Page 65: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Publishing

Page 66: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Publishing

Page 67: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Publishing

Page 68: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Deploying to IIS

• Point it to the wwwroot folder of published content

Page 69: Introduction to ASP.NET 5 and MVC 6 - Meetupfiles.meetup.com/16095872/ASPNET5MVC6.pdf · •Windows-only server that allows ASP.NET to be hosted outside IIS, •Runs directly on Http.Sys

Thank YouTwitter: @OvaisMehboob

Email: [email protected]