55
ASP.NET vNext Intro and Hands-On

ASP.NET vNext ANUG 20140817

Embed Size (px)

DESCRIPTION

Introduction to what is happening with ASP.NET vNext as of summer 2014. This is a mix of public information and my personal interpretations of announcements and open source ASP.NET code.

Citation preview

Page 1: ASP.NET vNext ANUG 20140817

ASP.NET vNextIntro and Hands-On

Page 2: ASP.NET vNext ANUG 20140817

Agenda

Introduction and my opinionsBreak + sandwichesHack

Page 3: ASP.NET vNext ANUG 20140817

About me

Christian HorsdalIndependent Consultant

www.horsdal-consult.dk

[email protected]

@chr_horsdal

Page 4: ASP.NET vNext ANUG 20140817

HighlightsK runtimeModularized .NETBin deployOWINLess dependent on Visual Studio

Page 5: ASP.NET vNext ANUG 20140817

ASP.NET 12 Years Ago

IIS

.NET BCL

ASP.NET

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

Caching SessionState

Page 6: ASP.NET vNext ANUG 20140817

ASP.NET Today

IIS

.NET BCL

ASP.NET

ASP.NET MVC ASP.NET Web API

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

et al.Caching Session

State

Page 7: ASP.NET vNext ANUG 20140817

ASP.NET – things not in Vnext

IIS

.NET BCL

ASP.NET

ASP.NET MVC ASP.NET Web API

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

et al.Caching Session

State

Page 8: ASP.NET vNext ANUG 20140817

ASP.NET vNext – Guiding PrinciplesNo dependency on System.Web

this is huge

Cross platform

Low friction

(this is my interpretation)

Page 9: ASP.NET vNext ANUG 20140817

No System.Web

The System.Web namespace supplies classes and interfaces that enable browser-server communication. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request; the HttpResponse class, which manages HTTP output to the client; and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for cookie manipulation, file transfer, exception information, and output cache control.

Page 10: ASP.NET vNext ANUG 20140817

No System.WebSystem.Web is at the very core of ASP.NET

ContextRequestResponseSessionPipeline (that nasty global.asax stuff)

WebForms is intimately coupled to System.Web

Page 11: ASP.NET vNext ANUG 20140817

No System.Web

MVC is not (so) tightly coupled to System.Web

Nor is WebAPI

Page 12: ASP.NET vNext ANUG 20140817

No System.WebYour MVC/WebAPI project may be, though

HttpContext, HttpRequest, HttpResponse

SessionState

Caching

Page 13: ASP.NET vNext ANUG 20140817

No System.WebUnless you want to…

Because legacy code

Because WebFormsWhich still will improved on

Page 14: ASP.NET vNext ANUG 20140817

ASP.NET – and things changes in Vnext

IIS

.NET BCL

ASP.NET

ASP.NET MVC ASP.NET Web API

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

Caching SessionState

Page 15: ASP.NET vNext ANUG 20140817

MVC + WebAPI…will be unified

One controller typeMicorsoft.AspNet.Mvc.Controller

Or POCO controllers

Page 16: ASP.NET vNext ANUG 20140817

MVC + WebAPIOne depedency injection solution

…registering ”services” during startup.…inject in all…including SignalR

Page 17: ASP.NET vNext ANUG 20140817

MVC + WebAPI

Poke around in code

Page 18: ASP.NET vNext ANUG 20140817

ASP.NET – and things changed in Vnext

IIS

.NET BCL

ASP.NET

ASP.NET MVC ASP.NET Web API

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

Caching SessionState

Page 19: ASP.NET vNext ANUG 20140817

Cloud Optimized Framework

Because cloud. CLOUD. CLOUD

Trimmed downOpt-in to more through NuGets

Not in GAC

Page 20: ASP.NET vNext ANUG 20140817

Framework not in GACBin deploy

Side-by-side deploy

Good or bad for operations?

Page 21: ASP.NET vNext ANUG 20140817

ASP.NET – and things changed in Vnext

IIS

.NET BCL

ASP.NET

ASP.NET MVC ASP.NET Web API

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

Caching SessionState

Page 22: ASP.NET vNext ANUG 20140817

Detour: OWINApplicaiton

Middleware

Middleware

Server

Middleware

Middleware

IDictionary<string, object>

Page 23: ASP.NET vNext ANUG 20140817

OWIN

using AppFunc = Func<IDictionary<string, object>, // Environment Task>; // Done

Page 24: ASP.NET vNext ANUG 20140817

OWIN – Request EnvironmentRequired Key NameYes "owin.RequestBody"Yes "owin.RequestHeaders"Yes "owin.RequestMethod"Yes "owin.RequestPath"Yes "owin.RequestPathBase"Yes "owin.RequestProtocol"Yes "owin.RequestQueryString"

Yes "owin.RequestScheme"

Page 25: ASP.NET vNext ANUG 20140817

OWIN – Response Environment

Required Key NameYes "owin.ResponseBody"Yes "owin.ResponseHeaders"No "owin.ResponseStatusCode"No "owin.ResponseReasonPhrase"

No"owin.ResponseProtocol"

Page 26: ASP.NET vNext ANUG 20140817

OWIN in vNext

public class Startup { public void Configure(IBuilder app) { app.UseOwin(x => x.UseNancy()); } }

Page 27: ASP.NET vNext ANUG 20140817

OWIN in vNext

public class Startup { public void Configure(IBuilder app) { var buildFunc = app.UseOwin(); buildFunc(next => MyApp); }

public Task MyApp(IDictionary<string, object> environment) { var responseText = "Hello World"; var responseBytes = Encoding.UTF8.GetBytes(responseText);

var responseStream = (Stream)environment["owin.ResponseBody"]; var responseHeaders = (IDictionary<string, string[]>)environment["owin.ResponseHeaders"];

responseHeaders["Content-Length"] = new string[] { responseBytes.Length.ToString(CultureInfo.InvariantCulture) }; responseHeaders["Content-Type"] = new string[] { "text/plain" };

return responseStream.WriteAsync(responseBytes, 0, responseBytes.Length); } }

Page 28: ASP.NET vNext ANUG 20140817

OWIN in vNext

public class Startup { public void Configure(IBuilder app) { app.UseOwin(x => x.UseNancy()); } }

Page 29: ASP.NET vNext ANUG 20140817

Startup.csChoose frameworks

MVCSignalRThird party

Setup OWIN pipeline

Page 30: ASP.NET vNext ANUG 20140817

Startup.csRead configuration

Format is configurable, default json

Setup DIAcross everything

Page 31: ASP.NET vNext ANUG 20140817

Startup.cs

Poke around in code

Page 32: ASP.NET vNext ANUG 20140817

ASP.NET vNEXT

Page 33: ASP.NET vNext ANUG 20140817

K RuntimeCommand line for all things vNext

Or so it seems it will be

K Version Manager (kvm)K Package Manager (kpm)K Runtime Environment (kre)

K

Page 34: ASP.NET vNext ANUG 20140817

K Runtime

Application

Frameworks (MVC, WebAPI, 3rd party) & OWIN middleware

KRE

CoreCLR FullCLR Mono

Page 35: ASP.NET vNext ANUG 20140817

K Version Manager

PS C:\projects\vNext-play\HelloNancy> kvm list

Active Version Runtime Architecture Location------ ------- ------- ------------ -------- 1.0.0-alpha2 svr50 x86 C:\Users\chors_000\.kre\packages 1.0.0-alpha2 svrc50 x86 C:\Users\chors_000\.kre\packages * 1.0.0-alpha3-10201 svr50 x86 C:\Users\chors_000\.kre\packages

PS C:\projects\vNext-play\HelloNancy> kvm use 1.0.0-alpha3*Adding C:\Users\chors_000\.kre\packages\KRE-svr50-x86.1.0.0-alpha3*\bin to process PATH

Page 36: ASP.NET vNext ANUG 20140817

K Version ManagerInstall KREsUpgrade KREs

Set KRE per processI.e. per powershell window

Page 37: ASP.NET vNext ANUG 20140817

K Package ManagerRestores NuGets

But slightly smarter – kinda

Packages application

Page 38: ASP.NET vNext ANUG 20140817

Detour: project.jsonSuperseedes package.configSuperseedes .csproj

{ "dependencies": { "Microsoft.AspNet.Server.IIS" : "1.0.0-alpha2", "Microsoft.AspNet.Server.WebListener" : "1.0.0-alpha2", "Microsoft.AspNet.Owin": "1.0.0-alpha2", "Nancy" : "0.24-Pre1412" }, "configurations" : { "net451" : { }, "k10" : { } }}

Page 39: ASP.NET vNext ANUG 20140817

project.jsonProjects are NuGet or class libraries

Same syntax

Interchangeable

More or less no difference

Page 40: ASP.NET vNext ANUG 20140817

project.json{ "dependencies": { "Microsoft.AspNet.Server.IIS" : "1.0.0-alpha2", "Microsoft.AspNet.Server.WebListener" : "1.0.0-alpha2", "Microsoft.AspNet.Owin": "1.0.0-alpha2", "Nancy" : "0.24-Pre1412" }, "configurations" : { "net451" : { }, "k10" : { } }}

Page 41: ASP.NET vNext ANUG 20140817

project.json

DOES NOT LIST ALL FILES IN PROJECT

Page 42: ASP.NET vNext ANUG 20140817

project.jsonCommands:

Arbitrary powershellNo more weird MSBuild mockery (I hope)

{ "dependencies": { "Microsoft.AspNet.Server.IIS" : "1.0.0-alpha2", "Microsoft.AspNet.Server.WebListener" : "1.0.0-alpha2", "Microsoft.AspNet.Owin": "1.0.0-alpha2", "Nancy" : "0.24-Pre1412" }, "commands": { "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000" }, "configurations" : { "net451" : { }, "k10" : { } }}

Page 43: ASP.NET vNext ANUG 20140817

KCommand line for KRE

Executes commands from project.json

In context of a KRE

Page 44: ASP.NET vNext ANUG 20140817

K + Roslyn

= dynamic compilation of entire site

Page 45: ASP.NET vNext ANUG 20140817

K, KPM, KVM, KRENo ties to Visual Studio

Point-in-case: Kulture

Page 46: ASP.NET vNext ANUG 20140817

HighlightsK runtimeModularized .NETBin deployOWINLess dependent on Visual Studio

Page 47: ASP.NET vNext ANUG 20140817

Why Do I Care?More OWINÞBetter opportunity for .NET OSSÞOWIN Middleware eco system will blossonÞ Nice modular way of working

Page 48: ASP.NET vNext ANUG 20140817

Why Do I Care?Modularized .NET + bin deployÞSmaller footprint on disk and memory (!)ÞFaster development from MS on some partsÞSide-by-side on different versions

Page 49: ASP.NET vNext ANUG 20140817

Why Do I Care?K and cross platform:

Broader potential developer crowdK as enabler for own toolingK as enabler for 3rd party / OSS tooling(and I’m not thinking about Jetbrains)

Page 50: ASP.NET vNext ANUG 20140817

Break

…and sandwiches

Page 51: ASP.NET vNext ANUG 20140817

Visual Studio 14 CTP*

Everybody got this???

Page 52: ASP.NET vNext ANUG 20140817

kGoto https://github.com/aspnet/HomeMake sure you allow remote scriptsRun the crazy command

Page 53: ASP.NET vNext ANUG 20140817

Exercise: URL shortener

Follow shortened url

HTTP GET “/shorts” Redirect to original URL

Submit URL to shortenHTTP POST “/” Shorten, store, return shortened URL

Get front pageHTTP GET “/” Web page with a simple form

Page 54: ASP.NET vNext ANUG 20140817

Storing shortened URLsCommon MongoHQ databaseCode at:

https://gist.github.com/horsdal/cbbf50bcbf3ff0904477See Facebook

Page 55: ASP.NET vNext ANUG 20140817

Things to do a long the wayPlay with dynamic compileSwitch KRE with kvmWrite some stupid OWIN middlewareDo the URL shortener in MVCDo the URL shortener in raw OWINK pack your app and move itAdd dependency to project.json, save and watch projects references

If CTP3 add xUnit test project as ASP.NET vNEXT class lib