Download - NET Core: a new .NET Platform
.NET Core 1.0A new .NET Platform
Alex Thissen
The real Netherlands
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
DEMOMeet .NET Core
.NET PlatformOn platforms, frameworks, runtimes and targets
.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
.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
.NET Platform Standard
.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
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
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
.NET FoundationFostering open development and collaboration • Focused on .NET FX• Apache 2 license mostly• No platform restrictions
From monolith to pebbles.NET Framework 4.6.x .NET Core 1.0
ASP.NET 5.0
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
.NET Core Technology Stack
OSX FreeBSDUbuntu Linux
.NET CLR .NET CoreCLR Mono CLR
.NET FX 4.6
Core basedapplications
Windows
CoreFX
Full CLR applications
DEMOBack to basics:.NET Core 1.0
Command-line firstOffering both a CLI and UI experience
Command-line firstMore than just Visual Studio
Text before UIReturn of the text files
• Everything from text files• Projects• Configuration• Preferences and options• Launch settings
• JSON is preferred data format
Cross-platform toolingA warm welcome to OSX and Linux
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
.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++
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
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)
NuGet all the thingsSimplify dependency management
• NuGet packages are unit of reference• Not assemblies
• Projects will: • build NuGet packages• reference NuGet
packages
Deploying ASP.NET Core applicationsXCopy deployment
With source code Without source code
Global tools• DNX console applications in a NuGet package• Installed globally• Runnable from command line.
Example: User-secret
ASP.NET Core 1.0
Ingredients to the mixProject KatanaOWIN npm NuGet
.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
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
ASP.NET components
MVC 6Unified Web Stack
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);
• 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
ASP.NET Core middleware
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
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>();
SymmetryTaking away the differences and embracing choice
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();
Configuration from JSON files• New hierarchical syntax with colons (:)• Items from JSON follow hierarchyvar connectionString = config["Data:DefaultConnection:ConnectionString";
{ "Data": { "DefaultConnection": { "ConnectionString": "…" } }}
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
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
ASP.NET MVC 6
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
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
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>();
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
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
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
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"
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"; }}
Logging
• Pluggable logging infrastructure provided• ILoggerFactory• Logging levels • from Debug up to Criticial
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()); }}
Looking forward
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
Tool
ing
Build
MacOS X
Docker client
Platf
orm
LinuxWindows Server
Pack
ages
.NET Core and Docker
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
Summary.NET Core is glimpse into future of .NET:• Modular• Unified in one .NET Platform• Cross-Platform
http://www.xpirit.com
Leading IT specialists in Microsoft Application Lifecycle Management,
Cloud, Enterprise Mobility & Security style