net core: a new .net platform

60
.NET Core 1.0 A new .NET Platform Alex Thissen

Upload: alex-thissen

Post on 13-Jan-2017

746 views

Category:

Presentations & Public Speaking


3 download

TRANSCRIPT

Page 1: NET Core: a new .NET Platform

.NET Core 1.0A new .NET Platform

Alex Thissen

Page 2: NET Core: a new .NET Platform

About me: Alex [email protected]

@alexthissen

Xbox Live: LX360Xpirit

Page 3: NET Core: a new .NET Platform

The real Netherlands

Page 4: NET Core: a new .NET Platform

Agenda• Creating a foundation: .NET Core 1.0• Providing a basis for web: ASP.NET Core 1.0• Building applications: ASP.NET MVC 6• Looking forward: Containers and micro services

• Summary• Questions and Answers• Discussion

Page 5: NET Core: a new .NET Platform

DEMOMeet .NET Core

Page 6: NET Core: a new .NET Platform

.NET PlatformOn platforms, frameworks, runtimes and targets

Page 7: NET Core: a new .NET Platform

.NET FRAMEWORK .NET CORE XAMARIN

APP

MOD

ELS

BASE

LIBR

ARIE

S

Base Class Library Core Library Mono Class Library

ASP.NET

Windows FormsWPF UWP

ASP.NET Core*

iOSAndroid

Compilers Languages Runtime components

COMMON INFRASTRUCTURE

OS X

.NET today—app models and libraries

Page 8: NET Core: a new .NET Platform

.NET FRAMEWORK .NET CORE XAMARIN

APP

MOD

ELS

BASE

LIBR

ARIE

S

Compilers Languages Runtime components

COMMON INFRASTRUCTURE

PCL reference assemblies

Reference implementati

on

My code

Implementation 3Implementation

2Implementation 1

.NET today—reusing code

Page 9: NET Core: a new .NET Platform

.NET Platform Standard

Page 10: NET Core: a new .NET Platform

.NET Platforms .NET FRAMEWORK .NET CORE XAMARIN

.NET STANDARD LIBRARYOne library to rule them all

ASP.NET

Windows FormsWPF UWP

ASP.NET Core

iOSAndroid

Compilers Languages Runtime components

COMMON INFRASTRUCTURE

OS XApp

Mod

el

Inno

vatio

n.N

ET In

nova

tion

TOOLS

Visual Studio

Visual StudioCode

Application code

Full implementations

Reference implementations

Page 11: NET Core: a new .NET Platform

ASP.NET Core and the Modern Web

Choose your editors and tools

Open Source with contributions Cross-Platform

Seamless transition from on-premises to cloud

Faster development cycleTotally modular

Fast

Where it all started

Page 12: NET Core: a new .NET Platform

Tenets from ASP.NET team

Command-line first• Facilitate cross-

platform• Visual Studio for

premium experience

Symmetry• Between command-

line and vs• Between server and

cloud• It just works by

default in the cloud and on-premises

Open source• All code visible

(even during development)

• Contributions• GitHub

Light-weight and Pay-as-you-go• Only include what

you use

Page 13: NET Core: a new .NET Platform

.NET FoundationFostering open development and collaboration • Focused on .NET FX• Apache 2 license mostly• No platform restrictions

Page 14: NET Core: a new .NET Platform

From monolith to pebbles.NET Framework 4.6.x .NET Core 1.0

ASP.NET 5.0

Page 15: NET Core: a new .NET Platform

Small recap on .NET runtimes and frameworks

Full .NET FX + CLR

• Entire API set in machine wide install at 200 MB

• Updated with OS• Ecosystem of existing

packages• Backward compatibility• Default for

Visual Studio 2015 projects

.NET CoreFX + CoreCLR

• Lean and modular runtime (11 MB)• Optimized for server• Small memory footprint

• Libraries in NuGet packages

• Framework deployed with app

• Different versions can run side-by-side

Mono/Native CLR

• Cross-Platform runtime for Linux and Mac OS X

• Together with Mono community

Page 16: NET Core: a new .NET Platform

.NET Core Technology Stack

OSX FreeBSDUbuntu Linux

.NET CLR .NET CoreCLR Mono CLR

.NET FX 4.6

Core basedapplications

Windows

CoreFX

Full CLR applications

Page 17: NET Core: a new .NET Platform

DEMOBack to basics:.NET Core 1.0

Page 18: NET Core: a new .NET Platform

Command-line firstOffering both a CLI and UI experience

Page 19: NET Core: a new .NET Platform

Command-line firstMore than just Visual Studio

Page 20: NET Core: a new .NET Platform

Text before UIReturn of the text files

• Everything from text files• Projects• Configuration• Preferences and options• Launch settings

• JSON is preferred data format

Page 21: NET Core: a new .NET Platform

Cross-platform toolingA warm welcome to OSX and Linux

Page 22: NET Core: a new .NET Platform

DNX - .NET Execution EnvironmentCode required to bootstrap and run an application

• Compilation system• SDK tools (DNVM, CLI)

• Native CLR hosts

Goals

• Change code and run• Expose metadata about the

runtime for others to query• Create a cached version of

your application's dependencies ("compilation")

Principles

• NuGet all the things• There is no such thing as

"design time"• Dependencies are always

described as what not where

Page 23: NET Core: a new .NET Platform

.NET Compilers• Roslyn: open-source C# and Visual Basic compilers with

rich code analysis APIs• RyuJIT: 64-bit next generation

JIT compiler, twice as fast• .NET Native

Experimental:• LLILC: LLVM based MSIL Compiler • IL to C++

Page 24: NET Core: a new .NET Platform

Compilers and runtimes in action• JIT: Just-in-Time

Fast compilation during runtime• AOT: Ahead of Time

Highly optimized machine code during build

CoreRT

.NET Native

Compiler

Single binary64 bit native code

CoreCLR

RyuJITLLILC

.NET assembliesIL code

.NET Native toolchain:RyuJIT (default)LLILC (future)IL to C++

Roslyn Compiler Platform

Build

AOT

Native codeJIT

CoreFX

Page 25: NET Core: a new .NET Platform

New project system.csproj is gone. Long live project.json

• Independent of Visual Studio• JSON files instead of VS artefacts• Every file is relevant• Unless stated otherwise

• Specific folder structure• Build for multiple target frameworks• .xproj for Visual Studio (for now)

Page 26: NET Core: a new .NET Platform

NuGet all the thingsSimplify dependency management

• NuGet packages are unit of reference• Not assemblies

• Projects will: • build NuGet packages• reference NuGet

packages

Page 27: NET Core: a new .NET Platform

Deploying ASP.NET Core applicationsXCopy deployment

With source code Without source code

Page 28: NET Core: a new .NET Platform

Global tools• DNX console applications in a NuGet package• Installed globally• Runnable from command line.

Example: User-secret

Page 29: NET Core: a new .NET Platform

ASP.NET Core 1.0

Page 30: NET Core: a new .NET Platform

Ingredients to the mixProject KatanaOWIN npm NuGet

Page 31: NET Core: a new .NET Platform

.NET Core Technology Stack

Host

MacOS XLinux

Self Hosted

“Helios”

IIS

IIS Native ModuleIIS Native Module

CLR Core CLR Mono CLR

.NET FX 4.6

ASP.NET Core 1.0

Windows

CoreFX

ASP.NET 4.6

ASP.NET MVC 6ASP.NET MVC 5

Now ASP.NET Core Module

Page 32: NET Core: a new .NET Platform

ASP.NET Core

MVC 6

ASP.NET Core 1.0 and MVC 6.0

Dependency Injection

Middleware

POCO

Environments

View ComponentsTag Helpers

Logging

Tool Support

Routing

Configuration

Page 33: NET Core: a new .NET Platform

ASP.NET components

MVC 6Unified Web Stack

Page 34: NET Core: a new .NET Platform

Middleware conceptually

Middleware stack• Static files• Security, authentication, CORS• Diagnostics, logging• Other cross-cutting concerns

Host process and server

Application and framework

Host

Application

Application Framework

Server

RequestDelegate delegate Task RequestDelegate(HttpContext context);

Page 35: NET Core: a new .NET Platform

• Pipeline of components between server and application• Connected through RequestDelegate

• Constructed at startup of app

vNext compatible application frameworks

Middleware architectureStacking pipeline parts

Host

Middlewarepipeline

Page 36: NET Core: a new .NET Platform

ASP.NET Core middleware

Page 37: NET Core: a new .NET Platform

public void Configure(IApplicationBuilder app) {

app.Map("/Nancy",  builder => { builder.UseRuntimeInfo();

builder.RunNancyFx(); });

app.UseCors();

app.UseMvc(cfg);

Cors

Use, Map and Run

ErrorPageapp.UseErrorPage();

RuntimeInfo

NancyFX

MVC+WebAPI

Application FX

Middleware

Page 38: NET Core: a new .NET Platform

Dependency Injection• DI is core part of runtime• Built-in DI for configuration and services• Default lightweight version available

• Wire up your own favorite IoC container ...• Autofac, Ninject, StructureMap, Unity, Castle Windsor

public void ConfigureServices(IServiceCollection services){ // Add EF services to the services container. services.AddEntityFramework(Configuration) .AddSqlServer() .AddDbContext<ApplicationDbContext>();

Page 39: NET Core: a new .NET Platform

SymmetryTaking away the differences and embracing choice

Page 40: NET Core: a new .NET Platform

Configuration• ASP.NET Core supports a variety of different

configuration options• By default JSON, XML, INI files, or environment variables• Command-line arguments (console applications)

• Configuration builder has fluent API

• Every call to Add overrides values from previous call

var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json")  .AddEnvironmentVariables();var config = builder.Build();

Page 41: NET Core: a new .NET Platform

Configuration from JSON files• New hierarchical syntax with colons (:)• Items from JSON follow hierarchyvar connectionString = config["Data:DefaultConnection:ConnectionString";

{ "Data": { "DefaultConnection": { "ConnectionString": "…" } }}

Page 42: NET Core: a new .NET Platform

Environments• ASP.NET now supports multiple environments• Environment variables are used to indicate which

environment application is running in, • Allows app to be configured appropriately• ASPNET_ENV or Hosting:Environment

• IHostingEnvironment service can be used for constructor injection• You can either use IHostingEnvironment to set up

different pipelines or use Startup<Environment> class

Page 43: NET Core: a new .NET Platform

Hosting in production• Built-in web server

(kestrel) based on libuv• Not built for internet

facing traffic – use a proxy • IIS• Nginx• HAProxy

• ASP.NET Core ModuleReplacement/fork of IISPlatformHandler

Kestrel

Proxy Kestrel

Kestrel

Page 44: NET Core: a new .NET Platform

ASP.NET MVC 6

Page 45: NET Core: a new .NET Platform

ASP.NET MVC 6• One set of concepts – remove duplication• Web UI and APIs• Smooth transition from Web Pages to MVC• Built DI first• Run on IIS or self-host• Based on new request pipeline in ASP.NET Core• Runs cloud-optimized

Page 46: NET Core: a new .NET Platform

Controllers• Single base class for MVC and

Web API• Not required

• POCO Controllers• No base class

• Combine Web API and MVC in 1 class• UI and REST endpoints

at one base URI

Page 47: NET Core: a new .NET Platform

Dependency Injection• DI is core part of runtime• Built-in DI for configuration and services• Default lightweight version available

• Wire up your own favorite IoC container ...• Autofac, Ninject, StructureMap, Unity, Castle Windsor,

SimpleInjectpublic void ConfigureServices(IServiceCollection services){ // Add EF services to the services container. services.AddEntityFramework(Configuration) .AddSqlServer() .AddDbContext<ApplicationDbContext>();

Page 48: NET Core: a new .NET Platform

Built-in DI Container• Register mappings in ConfigureServices of Startup• Default registrations• Lifetimes• Transient• Scoped• Singleton• Instance

• Rules for registering mapping• First one wins• Allows you to get ahead off default mappings

Sometimes better is worse than good enough

Page 49: NET Core: a new .NET Platform

ActivationActivation method Example

Constructor on classes MyController(ILog logger)

Attribute on field or property

[Activate]ILogger Logger { get;set; }

Attribute in action [FromServices] ILog logger

Directive in Razor page ILog logger

Inject those objects

@inject

Page 50: NET Core: a new .NET Platform

Tag HelpersGetting some help in Razor• Allow server-side code to participate in rendering

of HTML elements in Razor files• Target HTML elements based on element and

attribute names• Reduce explicit transitions between HTML and C#• Take advantage of composition and tooling

benefits in Visual Studio Code and 2015

Page 51: NET Core: a new .NET Platform

Custom Tag Helpersnamespace ASPNETMVC6.TagHelpers{ [HtmlTargetElement(“datetime")] public class DateTimeTagHelper : TagHelper { public override void Process(TagHelperContext context, TagHelperOutput output) { output.Content.SetContent(DateTime.Now.ToString()); } }}

// Inside Razor .cshtml file@addTagHelper "*,TagHelpers"

Page 52: NET Core: a new .NET Platform

RoutingShow me the way

• Familiar MVC 5 attribute based routing• Enabled by default• Special tokens: [controller] and [action][Route("api/Hello")]public class HelloController : Controller {      [Route] public string Get() { return "hello"; }}

[Route("api/[controller]")]public class HelloController : Controller {      [Route("home")] public string Index() { return "hello"; }}

Page 53: NET Core: a new .NET Platform

Logging

• Pluggable logging infrastructure provided• ILoggerFactory• Logging levels • from Debug up to Criticial

Page 54: NET Core: a new .NET Platform

View components

• Comparable to Web Forms’ UserControls• Different from

Partial Views• Combines code

and view as logical unit

User controls in MVC style

public class TopSessionsViewComponent : ViewComponent{ public IViewComponentResult Invoke() { return View(service.GetTop3Sessions()); }}

Page 55: NET Core: a new .NET Platform

Looking forward

Page 56: NET Core: a new .NET Platform

Microsoft Azure Service FabricA platform for reliable, hyperscale, microservice-based applications

Azure

WindowsServer Linux

Hosted Clouds

WindowsServer Linux

Service Fabric

Private Clouds

WindowsServer Linux

High Availability

Hyper-Scale

Hybrid OperationsHigh Density

Microservices

Rolling Upgrades Stateful

services

Low Latency Fast startup & shutdown

Container Orchestration & lifecycle management Replication &

FailoverSimple

programming models

Load balancing

Self-healingData Partitioning

Automated Rollback

Health Monitoring

Placement Constraints

Page 57: NET Core: a new .NET Platform

Tool

ing

Build

MacOS X

Docker client

Platf

orm

LinuxWindows Server

Pack

ages

.NET Core and Docker

Page 58: NET Core: a new .NET Platform

Getting started• Main starting point at http://dotnet.github.io • Open sourced at • http://github.com/dotnet • http://github.com/aspnet

• Help and feedback• JabbR: https://jabbr.net/#rooms/aspnetvnext • ASP.NET vNext forums: http://forums.asp.net/

• Nightly build for the adventurous• http://github.com/aspnet/home for instructions on how to do

bleeding edge

Page 59: NET Core: a new .NET Platform

Summary.NET Core is glimpse into future of .NET:• Modular• Unified in one .NET Platform• Cross-Platform

Page 60: NET Core: a new .NET Platform

http://www.xpirit.com

Leading IT specialists in Microsoft Application Lifecycle Management,

Cloud, Enterprise Mobility & Security style