asp.net vnext anug 20140817

Post on 24-May-2015

873 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

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.

TRANSCRIPT

ASP.NET vNextIntro and Hands-On

Agenda

Introduction and my opinionsBreak + sandwichesHack

About me

Christian HorsdalIndependent Consultant

www.horsdal-consult.dk

c.horsdal@gmail.com

@chr_horsdal

HighlightsK runtimeModularized .NETBin deployOWINLess dependent on Visual Studio

ASP.NET 12 Years Ago

IIS

.NET BCL

ASP.NET

HTTP Modules

ASP.NET WebForms

HTTP Handlers

Request pipeline

HTTP Context

Caching SessionState

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

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

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

this is huge

Cross platform

Low friction

(this is my interpretation)

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.

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

No System.Web

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

Nor is WebAPI

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

HttpContext, HttpRequest, HttpResponse

SessionState

Caching

No System.WebUnless you want to…

Because legacy code

Because WebFormsWhich still will improved on

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

MVC + WebAPI…will be unified

One controller typeMicorsoft.AspNet.Mvc.Controller

Or POCO controllers

MVC + WebAPIOne depedency injection solution

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

MVC + WebAPI

Poke around in code

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

Cloud Optimized Framework

Because cloud. CLOUD. CLOUD

Trimmed downOpt-in to more through NuGets

Not in GAC

Framework not in GACBin deploy

Side-by-side deploy

Good or bad for operations?

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

Detour: OWINApplicaiton

Middleware

Middleware

Server

Middleware

Middleware

IDictionary<string, object>

OWIN

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

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"

OWIN – Response Environment

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

No"owin.ResponseProtocol"

OWIN in vNext

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

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); } }

OWIN in vNext

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

Startup.csChoose frameworks

MVCSignalRThird party

Setup OWIN pipeline

Startup.csRead configuration

Format is configurable, default json

Setup DIAcross everything

Startup.cs

Poke around in code

ASP.NET vNEXT

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

K Runtime

Application

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

KRE

CoreCLR FullCLR Mono

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

K Version ManagerInstall KREsUpgrade KREs

Set KRE per processI.e. per powershell window

K Package ManagerRestores NuGets

But slightly smarter – kinda

Packages application

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" : { } }}

project.jsonProjects are NuGet or class libraries

Same syntax

Interchangeable

More or less no difference

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" : { } }}

project.json

DOES NOT LIST ALL FILES IN PROJECT

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" : { } }}

KCommand line for KRE

Executes commands from project.json

In context of a KRE

K + Roslyn

= dynamic compilation of entire site

K, KPM, KVM, KRENo ties to Visual Studio

Point-in-case: Kulture

HighlightsK runtimeModularized .NETBin deployOWINLess dependent on Visual Studio

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

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

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)

Break

…and sandwiches

Visual Studio 14 CTP*

Everybody got this???

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

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

Storing shortened URLsCommon MongoHQ databaseCode at:

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

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

top related