net core - not your daddy's dotnet
TRANSCRIPT
© Betabit Nederland B.V.
Oscar van [email protected]@oscarvantol
Rick van den [email protected]@rickvdbosch
.NET CoreNot your daddy’s DOT NET
© Betabit Nederland B.V.
Who’s who?
Oscar van Tol Rick van den Bosch
© Betabit Nederland B.V.
The plan
.NET Core - the basicsWhy the reboot.NET StandardTooling *EF Core *CaffeineASP.NET Core
ASP.NET Core – Web API *ASP.NET Core – MVC *
What’s next* == code!
© Betabit Nederland B.V.
.NET Core - the basics
© Betabit Nederland B.V.
.NET Core
“.NET Core is a general purpose development platform maintained by Microsoft and the .NET community on GitHub. It is cross-platform,
supporting Windows, macOS and Linux, and can be used in device, cloud, and embedded/IoT scenarios.”
source: https://docs.microsoft.com/en-us/dotnet/articles/core
© Betabit Nederland B.V.
What is .NET Core1/2
• Flexible deployment: Can be included in your app or installed side-by-side user- or machine-wide.
• Cross-platform: Runs on Windows, macOS and Linux; can be ported to
other OSes. The supported Operating Systems (OS), CPUs and application scenarios will grow over time, provided by Microsoft, other companies, and individuals.
• Command-line tools: All product scenarios can be exercised at the
command-line.
© Betabit Nederland B.V.
What is .NET Core 2/2
• Compatible: .NET Core is compatible with .NET Framework, Xamarin and Mono, via the .NET Standard Library.
• Open source: The .NET Core platform is open source, using MIT and
Apache 2 licenses. Documentation is licensed under CC-BY. .NET Core is a .NET Foundation project.
• Supported by Microsoft: .NET Core is supported by Microsoft, per
.NET Core Support
© Betabit Nederland B.V.
© Betabit Nederland B.V.
Why the reboot
.NET Framework was too monolithic Too many dependencies (preventing cross-platform) Maintaining compatibility slowed down Framework development Removed dependency on OS Faster startup New runtime next to full framework (maintaining compatibility)
© Betabit Nederland B.V.
.NET Standard
Multiple runtimes: • Reusing code? • Dependencies? • Creating libraries? • OS related stuff? (for example: disk access)
© Betabit Nederland B.V.
© Betabit Nederland B.V.
.NET Standard
We have Portable Class Libraries (PCL) for that. Right?
• Target ‘least common denominator’ API for platforms
• Not a sustainable model
© Betabit Nederland B.V.
.NET Standard
• A version of the .NET Standard is a definition of a collection of standard Api’s.
• A runtime can support one or more versions of the .NET Standard.
• A library can target one or more versions of the .NET Standard.
© Betabit Nederland B.V.
.NET Standard: versions
© Betabit Nederland B.V.
So what do we do with PCL?
© Betabit Nederland B.V.
.NET Standard 2.0
© Betabit Nederland B.V.
.NET Core SDK
Command line tools
Libraries & runtime
dotnet driver (CLI)Primary layerCross platform
© Betabit Nederland B.V.
DEMO.NET Core Tooling
© Betabit Nederland B.V.
dotnet.exe
newmigraterestorerunbuildtestpublishpack
Meer info: http://bit.ly/nyddn-cmds
© Betabit Nederland B.V.
EF Core
© Betabit Nederland B.V.
EF Core
“EF Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework data access technology. It is an object-relational mapper that enables .NET developers to work with a database using .NET
objects. It eliminates the need for most of the data-access code that developers usually need to write”
source: https://docs.microsoft.com/en-us/ef/core
© Betabit Nederland B.V.
EF Core
Lightweight
Extensible
Cross-platform
© Betabit Nederland B.V.
EF Core
Not complete!
EF6.x is still alive and will continue to be updated. https://github.com/aspnet/EntityFramework6
“very much a v1 product”
Not Supported: Complex/value types, Simple type conversions, Spatial data types, Many-to-many without join entity, Lazy loading, Simple ccommand interception, Stored procedure mapping, Update model from database, Seed data, …
© Betabit Nederland B.V.
Which one is right for you?
EF6.x most suitable for most applications
Use EF Core:• In new applications that do not require missing features• In applications that target .NET Core
“You should view the move from EF6.x to EF Core as a port rather than an upgrade”
© Betabit Nederland B.V.
DEMOEntity Framework Core
© Betabit Nederland B.V.
Hands on with .NET Core?
Workshop .NET Core@Betabit UtrechtHands on
Registration form available on the tables
© Betabit Nederland B.V.
WINACTIE
Wat: Security workshopWaar: Betabit UtrechtWanneer: 5 & 6 juni 2017
Lever het formulier vandaag in!
Let op! Maandag 5 juni is 2de pinksterdag
© Betabit Nederland B.V.
Lets have a <br>Warning: we really respect your privacy and EU law requirements require us to inform you that this caffeine break will contain cookies. [accept]
© Betabit Nederland B.V.
ASP.NET Core
© Betabit Nederland B.V.
ASP.NET Core
“ASP.NET Core is a new open-source and cross-platform framework for building modern cloud based internet connected applications, such as web
apps, IoT apps and mobile backends.”
source: https://docs.microsoft.com/en-us/aspnet/core
© Betabit Nederland B.V.
ASP.NET Core
ASP.NET Core != .NET Core
Can target .NET Core and Full Framework
Develop & run on Windows, Mac or Linux
© Betabit Nederland B.V.
Why ASP.NET Core?
ASP.NET 1st version: 15 years agoLots of added & evolved capabilities
Much leaner and more compact
No longer based on System.Web.dll (but on NuGet packages)Tighter securityReduced servicingImproved performanceDecreased costs in pay-per-use model
© Betabit Nederland B.V.
ASP.NET Core – Startup
Startup class is required
Constructor can accept dependencies provided by DIIHostingEnvironmentILoggerFactory
Must include Configure methodAdding middleware
Can include ConfigureServicesCalled before ConfigureSetup DI etc.
© Betabit Nederland B.V.
ASP.NET Core – Middleware
Assembled into pipeline
Handles requests and responses
Calls next or short-circuits the chain
In-line or reusable
Executed in order!Critical to security, performanceand functionality
© Betabit Nederland B.V.
ASP.NET Core – Middleware example
© Betabit Nederland B.V.
What’s ‘wrong’ here…???
© Betabit Nederland B.V.
ASP.NET Core – Configuration
Configure app based on a list of name-value pairs
Can be read at runtime from multiple sources
Supports• File formats (INI, JSON and XML)• Command-line arguments• Environment variables• In-memory .NET objects• An encrypted user store• Azure Key Vault• Custom providers (install or create)
© Betabit Nederland B.V.
ASP.NET Core – Options pattern
Uses custom options classes to represent a group of related settings
Enables using decoupled classes for each featureInterface Segregation Principle (ISP)Separation of Concerns
IOptionsSnapshot supports reloading configuration on file change
© Betabit Nederland B.V.
ASP.NET Core – Hosting
ASP.NET Core requires a host in which to execute
Must implement IWebHost
Typically created using WebHostBuilder
Responsible for application startup and lifetime management
© Betabit Nederland B.V.
ASP.NET Core – Web server
ASP.NET Core runs with an in-process HTTP Server implementation
Listens for HTTP Requests
Surfaces them to application as sets of request features composed into an HttpContext
ASP.NET Core ships with two server implementations:• Kestrel (Cross-platform, based on Libuv)• WebListener (Windows-only, based on Http.Sys)
© Betabit Nederland B.V.
ASP.NET Core – Kestrel
Included by default
Internal facing: just Kestrel
Internet facing: IIS, Nginx or Apache as reverse proxy
© Betabit Nederland B.V.
ASP.NET Core – WebListener
Internal facing: WebListener
Internet facing (without IIS): WebListener
Internal facing: Kestrel recommended, unless WebListener features needed
© Betabit Nederland B.V.
ASP.NET Core Web API
What's new?
• Nothing, it's gone• Use MVC 6 for REST• No major issues migrating
(Microsoft.AspNetCore.Mvc.WebApiCompatShim)
• Heads up: Json formatting now default in camelCase
© Betabit Nederland B.V.
DEMOASP.NET Core Web API
© Betabit Nederland B.V.
ASP.NET Core MVC
What’s new?
• wwwroot• Razor syntax• Tag helpers• Dependency Injection in Views• …
© Betabit Nederland B.V.
wwwroot
Meant for static files
Add static file middleware
URLs for static content are relative to wwwroot
Clean separation between code and static files
© Betabit Nederland B.V.
Razor & Tag helpers
© Betabit Nederland B.V.
DI into views
@inject (adds a ‘property’ to your view
Can be usefull for View-specific services (localization)
Maintain a Separation of Concerns
(Most of the) data your view displays should be passed in from the controller
Can be used to override services
Heads-up: register services you want to inject
© Betabit Nederland B.V.
DEMOASP.NET Core MVC
© Betabit Nederland B.V.
ASP.NET or ASP.NET Core?
© Betabit Nederland B.V.
Recap
.NET Core
Command line interface
.NET Standard
Entity Framework Core
ASP.NET Core
© Betabit Nederland B.V.
FINAL DEMO
© Betabit Nederland B.V.
FX: To Core or not to Core?.NET Core .NET FrameworkCross-platform needs Currently using .NETTargeting micro-services 3rd party libraries / NuGet packagesUsing Docker Techologies not (yet) supportedHigh performance & scalabilitySide by side .NET versions
© Betabit Nederland B.V.
What's next
source: https://github.com/dotnet/core/blob/master/roadmap.md
© Betabit Nederland B.V.
Did you know?
© Betabit Nederland B.V.
Resources
.NET Core Source Browser https://source.dot.net
dotnet.exe commands http://bit.ly/nyddn-cmds
Roadmaphttps://github.com/dotnet/core/blob/master/roadmap.md
© Betabit Nederland B.V.
Bedankt voor je aandacht
© Betabit Nederland B.V.
© Betabit Nederland B.V.