What's new in ASP.NET Core 1.0 (Formerly known as ASP.NET 5) Israel Dot NET Developers User Group April 2016

Flashback from 2002

So what has changed?

Where’s Waldo? Yonatan Mevorach .NET Web Developer at

.NET Core Overview • Open-sourced (MIT) • Cross-platform • Portable • Modular • "CLI first“ • Performance • A “Reboot”

Vision • “The audience is the 15-year-old girl who went to a hackathon… so then fast forward 10 or 15 years, when that 15-year-old girl starts facebook v2- .net's in the running” -- Scott Hanselman • “We need to get those things right to enable the next 5, 10, 15 years of innovation on .net” -- Damian Edwards

Open-sourced (MIT) • https://github.com/dotnet/core (Samples) • https://github.com/dotnet/coreclr (Runtime) • https://github.com/dotnet/corefx (Libraries) • https://github.com/dotnet/cli (Command Line) • .NET Core Design Reviews Videos

Open-sourced • https://github.com/dotnet/core (Samples) • https://github.com/dotnet/coreclr (Runtime) • https://github.com/dotnet/corefx (Libraries) • https://github.com/dotnet/cli (Command Line) • .NET Core Design Reviews Videos

Cross-platform

Modular & Portable • Application-local model instead of a Machine-wide model • Enables releasing updates in a much more agile fashion • Blogpost: Introducing .NET Core

Bye Bye GAC (Global Assembly Cache)

What’s missing • System.Data (partly) • System.Drawing • System.Xml.Xsl • System.Xml.Schema • System.Net.Mail • System.IO.Ports • … and more • Blogpost: Porting to .NET Core

NuGet • The primary experience for references and dependencies • No difference between 1st party .net dependencies and 3rd party dependencies • .NET Core is made up of many NuGet packages

NuGet • Use the right tool for the right job • NuGet is for .net code • NPM \ Bower is for scripts (jQuery, Angular, etc.) • GUI-less, autocomplete, auto download mode

Updating dependencies

Updating dependencies

Future of dependencies in VS

Bye Bye .csproj

project.json Replaces .csproj file • JSON instead of XML • All files in the dir are part of the project by default • Supports globbing

project.json • Dependencies (NuGet, other projects) • Frameworks • Docs: Project.json file

CLI First • Use whatever IDE \ Editor you want using OmniSharp • Build and run with the dotnet CLI tool • Getting started with .NET Core

DEMO Hello World

Offtopic: .NET Native • A tool to compile IL bytecode into native machine code Ahead of Time (AOT) • Great performance implications • In the early stages of development • About: .NET Ecosystem • Github: .NET Core Runtime (CoreRT)

ASP.NET Core 1.0 • Open-sourced (Apache) • Cross-platform • Portable • Modular • "CLI first“ • Performance

Open-sourced • • • • • • • • • • • • https://github.com/aspnet/Home https://github.com/aspnet/Mvc https://github.com/aspnet/DependencyInjection https://github.com/aspnet/Razor https://github.com/aspnet/EntityFramework https://github.com/aspnet/Identity https://github.com/aspnet/diagnostics/ https://github.com/aspnet/configuration https://github.com/aspnet/Hosting https://github.com/aspnet/StaticFiles https://github.com/aspnet/ResponseCaching https://github.com/aspnet/KestrelHttpServer • ASP.NET Community Standup

Open-sourced

ASP.NET Core 1.0 • Compatible with both .NET Core and .NET Framework 4.6 • Not tied to IIS • MVC and Web API Unification • Middleware • New Configuration model • Built-in Dependency Injection • Tag Helpers

Run ASP.NET Core, Run

What’s missing • SignalR • WebForms • Visual Basic support • F# support

DEMO Empty Web Application

Middleware • A Request\Response handling component • When put together they make up your HTTP request handling pipeline • The order in which you set up your middleware matters! It matches the order your Request delegate will be called

Middleware • Docs: Middleware

Middleware Everywhere! • Almost all of the ASP.NET functionality is now implemented as Middleware (e.g. Exception Handling, Static Files, Authentication, MVC, etc.) • Which means that • You can choose whether or not to use • Modify (since it’s modular & open source)

Bye Bye HTTP Handlers & HTTP Modules • Docs: Migrating HTTP Modules to Middleware

wwwroot • The root of the web app is now different than the root of the project • By default, the web app root folder is called wwwroot (configurable), and it’s under the project root folder • Helps you protect sensitive files

DEMO Web Application

Startup class • When your app start it will look for a Startup class to instantiate • And it will look for the Configure and ConfigureServices methods to call • Startup constructor – set up Configuration • Configure – set up Middleware • ConfigureServices – set up Service injection • Source Code: StartupLoader

Environment Variables

Configuration • The new configuration model provides is based on access to key/value pair that can be retrieved from a variety of providers • • • • • • In memory JSON file Environment variables XML file Command line parameters Custom (inherit from ConfigurationProvider) • Docs: Configuration

Bye Bye web.config

Configuration The order of providers matters

Secret Manager • Helps store sensitive data outside of your project tree • Intended for use in Development mode only • Does not encrypt the stored secrets • On Windows it’s stored at %APPDATA%\microsoft\UserSecrets<userSecretsId>\secrets.json • Docs: Safe Storage of Application Secrets

Nested Configuration

Dependency Injection • Dependency Injection is a technique for achieving loose coupling between classes • ASP.NET 5 is designed from the ground up to support and leverage dependency injection • Blogpost: Dependency Injection in ASP.NET Core

Dependency Injection • Supports Constructor Injection • Available service lifetime configuration • • • • Transient Scoped Singleton Instance • Docs: Dependency Injection

Dependency Injection • The built-in container provides a minimal feature set and is not intended to replace other containers • Does not support • Registering by convention • Multiple implementations per interface • Interceptors

Dependency Injection • You can replace the built-in container with any container that also implements IServiceProvider • Replace with • Autofac supports ASP.NET Core

Dynamic Development • Dynamic compilation saves you time by removing the need to compile the app every time you change it • Just edit, save, and refresh the browser. • Use without Visual Studio using dotnet-watch • Blogpost: Introducing ASP.NET 5

ASP- The story so far

MVC 6 • Unified stack for MVC and Web API apps • It’s just middleware • Routing • Razor • Serialization • Source Code: AddMvc()

Routing • MVC uses a generic Routing middleware that can also be used without MVC • Allows using inline constraints in MapRoute (int, bool, datetime, float, guid, length, range, alpha, regex, required) • Allows falling back to another route if a route handler decided it’s not relevant • Docs: Routing

Injecting services into Views • You can also inject services into Views using the new @inject Razor directive • Docs: Injecting Services Into Views

View Components • Invoked from a View and returns a Partial View • Includes the same separation-of-concerns and testability benefits found between a controller and view • Docs: View Components • Sample: TagHelperSample App

@await directive • Now that we can inject Services and ViewComponents into our View, we can potentially make the rendering much slower • The new @await Razor directive lets you render a Partial in an asynchronous manner

FlushAsync • Until today the Razor View Engine did not support flushing the HTTP response incrementally (Chunked Encoding) • Now this is possible by calling • Great for perceived performance • Wikipedia: Chunked transfer encoding

Tag Helpers

Tag Helpers • Everything looks like HTML • Plays nicely with syntax highlighting everywhere • But Tag Helpers aware tools (like VS) understand what’s not just HTML and provide extra intellisense • Attribute Tag Helpers render only some of the HTML attributes, not the entire element • You can use HTML to write HTML • Docs: Introduction to Tag Helpers

Tag Helpers • Attribute Tag Helpers • @Html.ActionLink → <a asp-section> • @Html.BeginForm → <form asp-controller> • @Html.LabelFor → <label asp-for> • Element Tag Helpers • <environment> Render the HTML within only in a certain env mode • <cache> Cache the rendered HTML within

Tag Helpers • Write your own Tag Helpers! • Just implement the TagHelper class • Docs: Authoring Tag Helpers • Sample: TagHelperSamples

Swagger • Swagger is a spec that defines a standard way of documenting your public API • Based on this Swagger tools can auto-generate documentation and language-specific SDKs • Use the Swagger Nuget packages to generate an interactive documentation site for your Web API in seconds

Kestrel • A new web server • Open-sourced • Cross-platform • Better performance • Based on libuv • I/O library (network, file system) • Primarily developed for node.js

Kestrel

Kestrel • Can run independently in production • But it’s advised to run behind a different web server in a reverse-proxy model • Windows: IIS • Using the HttpPlatformHandler module • Benefit from other IIS features (e.g. Windows Auth) • Linux: NGINX • Adding new features isn’t restricted by the host operating system (e.g. Websockets, HTTP 2.0)

2,300% More Requests/second compared to ASP.NET 4.6 https://twitter.com/scottgu/status/700549872726839296

KRE → DNX → dotnet CLI • May 12, ‘14 - Introducing ASP.NET vNext (alpha) • Nov 12, ‘14 - beta1 was released • Nov 18, ‘15 - ASP.NET 5 RC1 (Release Candidate 1) was released • Jan 19, ‘16 - ASP.NET 5 is renamed to ASP.NET Core 1.0 • Apr 14, ‘16 - Hanselman announces that RC2 is delayed in order to “re-plat” on top of the new .NET Core CLI

When to jump in? Right now* at asp.net/vnext * But know that you’re likely going to encounter out-of-date documentation (docs.asp.net), and work-in-progress code

Playing • https://github.com/aspnet/Home/ tree/dev/samples • https://github.com/aspnet/cli-samples • https://github.com/Microsoft-Build2016/CodeLabs-WebDev • https://github.com/aspnet/MusicStore

IMHO ASP.NET The Bad Parts ASP.NET Core Others The Bad Parts

Thank You! @cowchimp