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
Modular & Portable • Application-local model instead of a Machine-wide model • Enables releasing updates in a much more agile fashion • Blogpost: Introducing .NET Core
Slide 11
Bye Bye GAC (Global Assembly Cache)
Slide 12
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
Slide 13
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
Slide 14
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
Slide 15
Updating dependencies
Slide 16
Updating dependencies
Slide 17
Future of dependencies in VS
Slide 18
Bye Bye .csproj
Slide 19
project.json Replaces .csproj file • JSON instead of XML • All files in the dir are part of the project by default • Supports globbing
CLI First • Use whatever IDE \ Editor you want using OmniSharp • Build and run with the dotnet CLI tool
• Getting started with .NET Core
Slide 22
DEMO Hello World
Slide 23
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 • 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
Slide 28
Run ASP.NET Core, Run
Slide 29
What’s missing • SignalR • WebForms • Visual Basic support • F# support
Slide 30
DEMO Empty Web Application
Slide 31
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
Slide 32
Middleware
• Docs: Middleware
Slide 33
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)
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
Slide 36
DEMO Web Application
Slide 37
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
Slide 38
Environment Variables
Slide 39
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
Slide 40
Bye Bye web.config
Slide 41
Configuration
The order of providers matters
Slide 42
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
Slide 43
Nested Configuration
Slide 44
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 • 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
Slide 47
Dependency Injection • You can replace the built-in container with any container that also implements IServiceProvider • Replace
with
• Autofac supports ASP.NET Core
Slide 48
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
Slide 49
ASP- The story so far
Slide 50
MVC 6 • Unified stack for MVC and Web API apps • It’s just middleware • Routing • Razor • Serialization
• Source Code: AddMvc()
Slide 51
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
Slide 52
Injecting services into Views • You can also inject services into Views using the new @inject Razor directive
• Docs: Injecting Services Into Views
Slide 53
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
Slide 54
@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
Slide 55
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
Slide 56
Tag Helpers
Slide 57
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
Slide 58
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
Slide 59
Tag Helpers • Write your own Tag Helpers! • Just implement the TagHelper class
• Docs: Authoring Tag Helpers • Sample: TagHelperSamples
Slide 60
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
Slide 61
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
Slide 62
Kestrel
Slide 63
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)
Slide 64
2,300% More Requests/second compared to ASP.NET 4.6
https://twitter.com/scottgu/status/700549872726839296
Slide 65
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
Slide 66
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
Slide 67
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
Slide 68
IMHO
ASP.NET The Bad Parts
ASP.NET Core
Others The Bad Parts