asp.net core: the best of the new bits
TRANSCRIPT
![Page 2: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/2.jpg)
About Me
Twitter: @KenCenerelliEmail: [email protected]: kencenerelli.wordpress.comLinkedIn: linkedin.com/in/kencenerelli
Bio: Programmer Writer / Content Developer Microsoft MVP - Visual Studio and
Development Technologies Microsoft TechNet Wiki Guru Co-Organizer of CTTDNUG Technical reviewer of multiple books
CTTDNUG
Ken Cenerelli
![Page 3: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/3.jpg)
.NET CoreFirst things first…
![Page 4: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/4.jpg)
.NET 2016 – 10K foot view
Next gen JIT (RyuJIT)SIMD
Runtime Components
Compilers.NET Compiler Platform (Roslyn)Languages innovation
.NET Core 1.0 Libraries
.NET Framework 4.6 Libraries
NuGet packagesCommon
.NET Framework 4.6 .NET Core 1.0 Full .NET Framework for any scenario and
library support on WindowsModular libraries & runtime optimized
for server and cloud workloads
WPF ASP.NET (4 and Core 1.0)
Windows Forms
ASP.NET Core 1.0
Universal Windows Apps
Core CLR .Net Native
![Page 5: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/5.jpg)
5
About .NET Core• .NET Core is a subset of the .NET Framework• Many .NET Framework components are not in .NET Core• .NET Core is completely modularized. Each component is
distributed via NuGet• Apps can be updated independently and do not rely on
major framework releases• Deployment package includes everything needed to run• .NET Core will run on Linux, Windows, and OSX
![Page 6: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/6.jpg)
6
Two parts of .NET Core•Runtime/Libraries:• CLR, libraries, compilers, etc.•Won’t change before RTM
•Tooling:• Supports .NET Core and ASP.NET Core, including the new command line tools and bits that plug into Visual Studio & Visual Studio Code•Will change before RTM
![Page 7: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/7.jpg)
7
DifferencesFeature .NET Framework .NET CoreLibrary Installation Centralised Distributed with each app
Updates One big update. You better get your app ready
Updates to framework are independent of app.
Update NuGet packages when you are ready
Platforms Windows is the only one for me
I love everyone! Windows, OSX, Linux
Base Class Library All the things! You get the entire BCL
All the things!You get the entire BCL
Credit: https://gooroo.io/GoorooTHINK/Article/16732/Introduction-to-NET-Core/22177
![Page 9: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/9.jpg)
9
Strange Times…
![Page 10: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/10.jpg)
Visual Studio 2015 and ASP.NET Core: Support for npm, bower, gulp, grunt, etc.
npm bower grunt gulp
![Page 11: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/11.jpg)
Responsive and plug-in free
http://bradfrost.com/blog/post/this-is-the-web/
![Page 12: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/12.jpg)
Responsive and plug-in free
http://bradfrost.com/blog/post/this-is-the-web/
![Page 13: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/13.jpg)
Responsive and plug-in free
http://bradfrost.com/blog/post/this-is-the-web/
![Page 14: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/14.jpg)
ASP.NET Core
![Page 15: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/15.jpg)
What about ASP.NET 5?
• ASP.NET Core 1.0 was previously called ASP.NET 5• It was renamed in January 2016• You may still see it referred to as ASP.NET 5 in
Visual Studio and in some docs• Was updated in latest ASP.NET Core Release
Candidate 2
![Page 16: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/16.jpg)
ASP.NET 4.6
ASP.NET 4.6 and ASP.NET Core 1.0
ASP.NET Core 1.0
.NET Framework 4.6
.NET framework libraries
Compilers and runtime components (.NET Compiler Platform: Roslyn, C#, VB, F# Languages, RyuJIT, SIMD)
.NET Core 1.0
.NET core libraries
![Page 17: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/17.jpg)
ASP.NET Core 1.0 Roadmap
https://github.com/aspnet/home/wiki/roadmap
Milestone Release weekBeta6 27 Jul 2015Beta7 2 Sep 2015Beta8 15 Oct 2015RC1 Nov 2015RC2 mid-May 20161.0.0 late-June 2016
![Page 18: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/18.jpg)
.NET 2016 – 10K foot view
Next gen JIT (RyuJIT)SIMD
Runtime Components
Compilers.NET Compiler Platform (Roslyn)Languages innovation
.NET Core 1.0 Libraries
.NET Framework 4.6 Libraries
NuGet packagesCommon
.NET Framework 4.6 .NET Core 1.0 Full .NET Framework for any scenario and
library support on WindowsModular libraries & runtime optimized
for server and cloud workloads
WPF ASP.NET (4 and Core 1.0)
Windows Forms
ASP.NET Core 1.0
Universal Windows Apps
Core CLR .Net Native
![Page 19: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/19.jpg)
ASP.NET 2016 in a Nutshell
.NET Framework 4.6 .NET Core 1.0 Full .NET Framework for any scenario and
library support on WindowsModular libraries & runtime optimized
for server and cloud workloads
ASP.NET 4.6 / System.Web
MVC 5.x
ASP.NET Core 1.0 features:MVC + Web API
Core CLR .Net NativeASP.NET Core 1.0
Web API 2.2
WebForms
Visual Studio (C# in both, VB.NET coming soon to ASP.NET Core)
![Page 20: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/20.jpg)
ASP.NET Core 1.0 – Key Values
Choose your Editors and Tools
Open Source with Contributions Cross-PlatformOSS
Seamless transition from on-premises to cloud
Faster Development CycleTotally Modular
Fast
![Page 21: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/21.jpg)
21
ASP.NET Core ~ What is it?• ASP.NET Core 1.0 is a console app• In RC1, an ASP.NET application was a class library that contained a
Startup.cs class• As of RC2, an ASP.NET Core application is a .NET Core Console
application that calls into ASP.NET specific libraries• So code that used to live in the ASP.NET Hosting libraries
and automatically runs your Startup.cs now lives inside a Program.cs
![Page 22: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/22.jpg)
22
ASP.NET Core ~ The features•Hosting• Kestrel, Startup
•Middleware• Routing, authentication, static files, diagnostics, error handling, session, CORS, localization, custom
•Dependency Injection•Configuration• Logging• Identity
![Page 23: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/23.jpg)
23
ASP.NET Core ~ Which editors & IDEs?•Visual Studio 2015 Update 2 including Community•Visual Studio Code with C# extension•An OmniSharp-enabled editor:• Atom • Emacs
• Brackets • Sublime Text• Yeoman • Vim
![Page 24: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/24.jpg)
24
ASP.NET Core ~ What can you do?•ASP.NET•MVC Web Apps in C#•Web API apps• Console apps• .NET Core compatible class library
•Signal R and Web Pages are coming after RTM
![Page 25: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/25.jpg)
MVC + Web API + Web Pages =
ASP.NET Core MVC
![Page 26: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/26.jpg)
26
ASP.NET Core MVC•One set of concepts – remove duplication•Web UI and Web APIs•Built on ASP.NET Core•Supports .NET Core•Runs on IIS or self-hosted•Deep integration with DI
![Page 27: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/27.jpg)
OWIN (Open Web Interface for .NET)• OWIN in an open, community owned specification• OWIN defines pluggable middleware and hosting• ASP.NET 4.5 and ASP.NET Core 1.0 both support OWIN
![Page 28: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/28.jpg)
28
Deployment portability•Two main models:• Portable Apps• Self-contained Apps
![Page 29: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/29.jpg)
29
Portable Apps•Default application type in .NET Core•Require .NET Core to be installed on the target machine•Your application is portable between installations of .NET Core•No need to decide upfront which OSes your app will run on
![Page 30: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/30.jpg)
30
Self-contained Apps•All app dependencies, including the .NET Core runtime, is part of the application•The app is larger, but also capable of running on any .NET Core supported platforms with the correct native dependencies•Need to make an explicit choice which platforms your application needs to run on during dev
![Page 31: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/31.jpg)
31
Setting Portability• Portable: • Self Contained:• Target .NET Core
libraries in project.json
• Remove any "type": "platform" properties
• Add a runtimes node in your project.json
• •
![Page 32: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/32.jpg)
Tooling Changes
![Page 33: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/33.jpg)
33
What’s new in ASP.NET Core RC2?• .NET CLI (SDK) and IDE updates•Tag Helpers• IIS support baked in•Host RC2 apps in Azure App Service•Docker support with a new version of Docker Tools for Visual Studio 2015
![Page 34: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/34.jpg)
34
ASP.NET Core SDK•The .NET Core SDK includes enough software to build an app•The SDK gives you both the .NET Core Tools and a copy of .NET Core•https://www.microsoft.com/net/core#windows
![Page 35: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/35.jpg)
DemoASP.NET Core 1.0 from the SDK
![Page 36: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/36.jpg)
36
ASP.NET Core IDE•The best way to develop with .NET Core on Windows is to download the Visual Studio official MSI Installer and the latest NuGet Manager extension for Visual Studio•https://www.microsoft.com/net/core#windows
![Page 37: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/37.jpg)
DemoASP.NET Core 1.0 from the IDE
![Page 38: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/38.jpg)
TagHelpers: Evolution of HTML Forms
•HTML helpers expressed as tagsEx. Instead of: @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })Write this: <label asp-for="UserName" class="col-md-2 control-label"></label>
• Easier to customize with more attributes•Work seamlessly with the HTML editor•Markup now looks like HTML and it comes with full IntelliSense
![Page 39: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/39.jpg)
TagHelpers
![Page 40: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/40.jpg)
DemoTagHelpers
![Page 41: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/41.jpg)
41
What about Entity Framework?•EF6.x most current and runs on .NET Framework 4.6•Entity Framework 7 renamed to Entity Framework Core 1.0•EF Core is a new code base that does not inherit all the features and API surface of EF6.x•EF6.x will continue to be a supported for some time
![Page 42: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/42.jpg)
42
When to use EF Core?•EF6.x will still be the most suitable choice for most applications•EF Core recommended for:•New applications that do not need features that are not yet implemented in EF Core• Applications that target .NET Core, such as Universal Windows Platform (UWP) and ASP.NET Core apps
![Page 43: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/43.jpg)
Web APIs
![Page 44: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/44.jpg)
In ASP.NET 4.6 – Separate Stack
ASP.NET Core
Web API
JSON XML
Web Forms
HTML
MVCWeb Pages
![Page 45: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/45.jpg)
In ASP.NET Core:API services are an ASP.NET Core feature
![Page 46: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/46.jpg)
Microsoft /web
®
Sample Read-only Model and Controllerpublic class Person{ public int Id { get; set; } public string Name { get; set; }}
Step 1:Create a Model
[Route("api/[controller]")]public class PersonController : Controller{ List<Person> people; public PersonController() { this.people = new List<Person>(); this.people.AddRange(new Person[] { new Person { Id = 1, Name = "Chuck Norris" }, new Person { Id = 2, Name = "David Carradine" }, new Person { Id = 3, Name = "Bruce Lee" } }); }}
Step 2:Make an API Controller
![Page 47: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/47.jpg)
Microsoft /web
®
Read-only Controller Actions to return data// GET /api/person[HttpGet]public IEnumerable<Person> Get(){ return this.people;}
Step 3:Return everything
// GET /api/person/5[HttpGet("{id}")]public Person Get(int id){ return this.people.FirstOrDefault(x => x.Id == id);}
Step 4:Return one item
![Page 48: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/48.jpg)
Routing a Web APIapp.UseMvc(routes =>{ routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}");});
Routing:Familiar syntax, conventional approach
[Route("api/[controller]")]public class PersonController : Controller {
[HttpGet("{id}")] public Person Get(int id) { /* ... */ }}
Attribute routing:Easy to configure
![Page 49: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/49.jpg)
ResourcesFeedback and questions http://asp.nethttp://get.asp.nethttp://docs.asp.nethttp://aka.ms/webcamps-training-kit
![Page 50: ASP.NET Core: The best of the new bits](https://reader030.vdocument.in/reader030/viewer/2022032613/587f11c41a28abc26f8b71ff/html5/thumbnails/50.jpg)