+ All Categories
Home > Software > .Net Core - not your daddy's dotnet

.Net Core - not your daddy's dotnet

Date post: 13-Apr-2017
Category:
Upload: rick-van-den-bosch
View: 181 times
Download: 1 times
Share this document with a friend
59
© Betabit Nederland B.V. Oscar van Tol [email protected] @oscarvantol Rick van den Bosch [email protected] @rickvdbosch .NET Core Not your daddy’s DOT NET
Transcript
Page 1: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Oscar van [email protected]@oscarvantol

Rick van den [email protected]@rickvdbosch

.NET CoreNot your daddy’s DOT NET

Page 2: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Who’s who?

Oscar van Tol Rick van den Bosch

Page 3: .Net Core - not your daddy's dotnet

© 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!

Page 4: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

.NET Core - the basics

Page 5: .Net Core - not your daddy's dotnet

© 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 

Page 6: .Net Core - not your daddy's dotnet

© 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.

Page 7: .Net Core - not your daddy's dotnet

© 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

Page 8: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Page 9: .Net Core - not your daddy's dotnet

© 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)

Page 10: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

.NET Standard

Multiple runtimes: • Reusing code? • Dependencies? • Creating libraries? • OS related stuff? (for example: disk access)

Page 11: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Page 12: .Net Core - not your daddy's dotnet

© 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

Page 13: .Net Core - not your daddy's dotnet

© 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.

Page 14: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

.NET Standard: versions

Page 15: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

So what do we do with PCL?

Page 16: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

.NET Standard 2.0

Page 17: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

.NET Core SDK

Command line tools

Libraries & runtime

dotnet driver (CLI)Primary layerCross platform

Page 18: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

DEMO.NET Core Tooling

Page 19: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

dotnet.exe

newmigraterestorerunbuildtestpublishpack

Meer info: http://bit.ly/nyddn-cmds

Page 20: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

EF Core

Page 21: .Net Core - not your daddy's dotnet

© 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

Page 22: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

EF Core

Lightweight

Extensible

Cross-platform

Page 23: .Net Core - not your daddy's dotnet

© 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, …

Page 24: .Net Core - not your daddy's dotnet

© 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”

Page 25: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

DEMOEntity Framework Core

Page 26: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Hands on with .NET Core?

Workshop .NET Core@Betabit UtrechtHands on

Registration form available on the tables

Page 27: .Net Core - not your daddy's dotnet

© 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

Page 28: .Net Core - not your daddy's dotnet

© 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]

Page 29: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

ASP.NET Core

Page 30: .Net Core - not your daddy's dotnet

© 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

Page 31: .Net Core - not your daddy's dotnet

© 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

Page 32: .Net Core - not your daddy's dotnet

© 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

Page 33: .Net Core - not your daddy's dotnet

© 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.

Page 34: .Net Core - not your daddy's dotnet

© 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

Page 35: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

ASP.NET Core – Middleware example

Page 36: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

What’s ‘wrong’ here…???

Page 37: .Net Core - not your daddy's dotnet

© 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)

Page 38: .Net Core - not your daddy's dotnet

© 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

Page 39: .Net Core - not your daddy's dotnet

© 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

Page 40: .Net Core - not your daddy's dotnet

© 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)

Page 41: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

ASP.NET Core – Kestrel

Included by default

Internal facing: just Kestrel

Internet facing: IIS, Nginx or Apache as reverse proxy

Page 42: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

ASP.NET Core – WebListener

Internal facing: WebListener

Internet facing (without IIS): WebListener

Internal facing: Kestrel recommended, unless WebListener features needed

Page 43: .Net Core - not your daddy's dotnet

© 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

Page 44: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

DEMOASP.NET Core Web API

Page 45: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

ASP.NET Core MVC

What’s new?

• wwwroot• Razor syntax• Tag helpers• Dependency Injection in Views• …

Page 46: .Net Core - not your daddy's dotnet

© 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

Page 47: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Razor & Tag helpers

Page 48: .Net Core - not your daddy's dotnet

© 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

Page 49: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

DEMOASP.NET Core MVC

Page 50: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

ASP.NET or ASP.NET Core?

Page 51: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Recap

.NET Core

Command line interface

.NET Standard

Entity Framework Core

ASP.NET Core

Page 52: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

FINAL DEMO

Page 53: .Net Core - not your daddy's dotnet

© 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

Page 54: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

What's next

source: https://github.com/dotnet/core/blob/master/roadmap.md

Page 55: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Did you know?

Page 56: .Net Core - not your daddy's dotnet

© 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

Page 57: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.

Page 58: .Net Core - not your daddy's dotnet

Bedankt voor je aandacht

© Betabit Nederland B.V.

Page 59: .Net Core - not your daddy's dotnet

© Betabit Nederland B.V.


Recommended