Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

.NET Core: a new .NET Platform

1,107 views

Published on

Microsoft is working hard to modernize the .NET Platform. There are great new frameworks and tools coming, such as .NET Core and ASP.NET Core. The amount of new things is overwhelming, with multiple .NET Platforms (.NET Framework, Unified Windows Platform, .NET Core), multiple runtimes (CoreCLR, CLR, CoreRT), multiple compilers (Roslyn, RyuJIT, .NET Native and LLILC) and much more. This session will bring you up to speed on all this new Microsoft technology, focusing on .NET Core.
But, we will also take a look at the first framework implementation on top op .NET Core for the Web: ASP.NET Core 1.0. You will learn about ASP.NET Core 1.0 and how it is different from ASP.NET 4.6. This will include Visual Studio 2015 support, cross-platform ASP.NET Core and command-line tooling for working with ASP.NET Core and .NET Core projects.
After this session you know where Microsoft is heading in the near future. Be prepared for a new .NET Platform.

  • Be the first to comment

.NET Core: a new .NET Platform

  1. 1. .NET Core 1.0 A new .NET Platform Alex Thissen
  2. 2. About me: Alex Thissen athissen@xpirit.com @alexthissen Xbox Live: LX360Xpirit
  3. 3. The real Netherlands
  4. 4. 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
  5. 5. DEMOMeet .NET Core
  6. 6. .NET Platform On platforms, frameworks, runtimes and targets
  7. 7. .NET FRAMEWORK .NET CORE XAMARIN APP MODELS BASE LIBRARIES * .NET today—app models and libraries
  8. 8. .NET FRAMEWORK .NET CORE XAMARIN APP MODELS BASE LIBRARIES .NET today—reusing code
  9. 9. .NET Platform Standard
  10. 10. .NET Platforms .NET FRAMEWORK .NET CORE XAMARIN TOOLS
  11. 11. 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
  12. 12. 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
  13. 13. .NET Foundation Fostering open development and collaboration • Focused on .NET FX • Apache 2 license mostly • No platform restrictions
  14. 14. From monolith to pebbles .NET Framework 4.6.x .NET Core 1.0 ASP.NET 5.0
  15. 15. 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
  16. 16. .NET Core Technology Stack OSX FreeBSD Ubuntu Linux .NET CLR .NET CoreCLR Mono CLR .NET FX 4.6 Core based applications Windows CoreFX Full CLR applications
  17. 17. DEMOBack to basics: .NET Core 1.0
  18. 18. Command-line first Offering both a CLI and UI experience
  19. 19. Command-line first More than just Visual Studio
  20. 20. Text before UI Return of the text files • Everything from text files • Projects • Configuration • Preferences and options • Launch settings • JSON is preferred data format
  21. 21. Cross-platform tooling A warm welcome to OSX and Linux
  22. 22. DNX - .NET Execution Environment Code 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
  23. 23. .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++
  24. 24. 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 binary 64 bit native code CoreCLR RyuJIT LLILC .NET assemblies IL code .NET Native toolchain: RyuJIT (default) LLILC (future) IL to C++ Roslyn Compiler Platform Build AOT Native codeJIT CoreFX
  25. 25. 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)
  26. 26. NuGet all the things Simplify dependency management • NuGet packages are unit of reference • Not assemblies • Projects will: • build NuGet packages • reference NuGet packages
  27. 27. Deploying ASP.NET Core applications XCopy deployment With source code Without source code
  28. 28. Global tools • DNX console applications in a NuGet package • Installed globally • Runnable from command line. Example: User-secret
  29. 29. ASP.NET Core 1.0
  30. 30. Ingredients to the mix Project KatanaOWIN npm NuGet
  31. 31. .NET Core Technology Stack Host MacOS X Linux 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
  32. 32. ASP.NET Core MVC 6 ASP.NET Core 1.0 and MVC 6.0 Dependency Injection Middleware POCO Environments View Components Tag Helpers Logging Tool Support Routing Configuration
  33. 33. ASP.NET components MVC 6 Unified Web Stack
  34. 34. Middleware conceptually Middleware stack • Static files • Security, authentication, CORS • Diagnostics, logging • Other cross-cutting concerns Host process and server Application and framework RequestDelegate delegate Task RequestDelegate(HttpContext context);
  35. 35. • Pipeline of components between server and application • Connected through RequestDelegate • Constructed at startup of app vNext compatible application frameworks Middleware architecture Stacking pipeline parts Host Middleware pipeline
  36. 36. ASP.NET Core middleware
  37. 37. public void Configure(IApplicationBuilder app) { app.Map("/Nancy", builder => { builder.UseRuntimeInfo(); builder.RunNancyFx(); }); app.UseCors(); app.UseMvc(cfg); Use, Map and Run app.UseErrorPage(); Application FX Middleware
  38. 38. 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>();
  39. 39. Symmetry Taking away the differences and embracing choice
  40. 40. 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();
  41. 41. Configuration from JSON files • New hierarchical syntax with colons (:) • Items from JSON follow hierarchy var connectionString = config["Data:DefaultConnection:ConnectionString"; { "Data": { "DefaultConnection": { "ConnectionString": "…" } } }
  42. 42. 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
  43. 43. 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 Module Replacement/fork of IISPlatformHandler
  44. 44. ASP.NET MVC 6
  45. 45. 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
  46. 46. 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
  47. 47. 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, SimpleInject public void ConfigureServices(IServiceCollection services) { // Add EF services to the services container. services.AddEntityFramework(Configuration) .AddSqlServer() .AddDbContext<ApplicationDbContext>();
  48. 48. 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
  49. 49. Activation Activation 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
  50. 50. Tag Helpers Getting 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
  51. 51. Custom Tag Helpers namespace 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"
  52. 52. Routing Show 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"; } }
  53. 53. Logging • Pluggable logging infrastructure provided • ILoggerFactory • Logging levels • from Debug up to Criticial
  54. 54. 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()); } }
  55. 55. Looking forward
  56. 56. Microsoft Azure Service Fabric A platform for reliable, hyperscale, microservice-based applications Azure Windows Server Linux Hosted Clouds Windows Server Linux Service Fabric Private Clouds Windows Server Linux High Availability Hyper-Scale Hybrid Operations High Density Microservices Rolling Upgrades Stateful services Low Latency Fast startup & shutdown Container Orchestration & lifecycle management Replication & Failover Simple programming models Load balancing Self-healingData Partitioning Automated Rollback Health Monitoring Placement Constraints
  57. 57. ToolingBuild MacOS X Docker client Platform Linux Windows Server Packages .NET Core and Docker
  58. 58. 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
  59. 59. Summary .NET Core is glimpse into future of .NET: • Modular • Unified in one .NET Platform • Cross-Platform
  60. 60. http://www.xpirit.com Leading IT specialists in Microsoft Application Lifecycle Management, Cloud, Enterprise Mobility & Security style

×