ASP.NET Core Demos

Post on 21-Mar-2017

116 views 1 download

transcript

ASP.NET CORE QUICK START

ERIK NORENSolutions ArchitectSoftware Developer 15+ YearsSoftware Tinkerer Since Commodore 64Hardware HobbyistTwitter: @ErikNorenGitHub: ErikNoren

ASP.NET CORE QUICK START.NET Core or .NET Framework

ASP.NET Core on…

.NET FRAMEWORK• Easy to Add Project

References• Windows Only• Create Libraries as Class

Library

.NET CORE• Primarily Leverage NuGet

Packages• Cross Platform• Start with Portable Class

Library then convert to .NET Standard

ASP.NET CORE

• Developed the same regardless if you choose .NET Core or .NET Framework• .NET Core and .NET Framework don’t have feature parity so some differences there

• Is a Console Application with a built-in web server (Kestrel)• Integrates Dependency Injection in a smart way and takes advantage of

knowing DI is available from the start.• Heavy use of NuGet packages and separation of abstractions from

implementation make DI into class libraries easy.

ASP.NET CORE QUICK STARTConfiguration

CONFIGURATION• Multiple Providers for Different Sources

• JSON Files, Environment Variables, INI Files, XML Files, Command Line Switches

• Configuration Values Stored in Single IConfiguration Object• Configuration Sources Converted to Key Value Pairs• Key Names are Flattened Hierarchy Using Colon Delimiters

• Key• Key:SubKey:AnotherSubKey

• Bind Configuration to POCO Object for Easy Use

CONFIGURATION

SOURCE{ “Version”: “1.0.preview1”, “Build” : { “Target”: “Release”, “Date”: “2017-02-16” }}

ICONFIGURATIONVersion = 1.0.preview1Build:Target = ReleaseBuild:Date = 2017-02-16

CONFIGURATION

• Added to DI Container as Singleton• IOptions<MySettings>• IOptionsSnapshot<MySettings>• IOptionsMonitor<MySettings>

• services.Configure<MySettings>(…)• Settings at time of application start• Settings as they currently are*• Settings as they currently are**

*Provider must support ReloadOnChange. Available in version 1.1.0**Provider must support ReloadOnChange. Has change event you can hook to detect changes.

ASP.NET CORE QUICK STARTConfiguration Demo

ASP.NET CORE QUICK STARTLogging

LOGGING

• ILoggerFactory can be injected to set up and configure logging• ILogger<T> can be injected in constructors to log messages• ILogger comes from Microsoft.Extensions.Logging.Abstractions• Easy to include into other projects using the interface• Dependency Injection will inject the implementation from the application• Avoid circular references, shared classes, etc.• Change logging provider in container with no application code changes

ASP.NET CORE QUICK STARTLogging Demo

ASP.NET CORE QUICK STARTClass Library References

Class Library References• Separating logic into separate projects is common• .NET Framework projects continue to work as they always have• .NET Core requires Portable Class Libraries targeting .NET Standard• NuGet Packages can contain both .NET Framework and .NET Core

libs• To see if a NuGet package is compatible, look at its dependencies• .NET Framework 4x will work in ASP.NET Core using .NET Framework• .NET Standard 1.x will work in ASP.NET Core using .NET Core

ASP.NET CORE QUICK STARTClass Library References Demo

QUESTIONS?Erik NorenSolutions ArchitectSoftware Developer 15+ YearsSoftware Tinkerer Since Commodore 64Hardware HobbyistTwitter: @ErikNorenGitHub: ErikNoren

RESOURCES

• Demo Code Samples - https://github.com/ErikNoren/AspNetCoreDemos• ASP.NET Core – https://www.asp.net/core• ASP.NET Core Source – https://github.com/aspnet/home• Microsoft Docs – https://docs.microsoft.com/• .NET Standard – https://github.com/dotnet/standard• .NET Core Roadmap – https://github.com/dotnet/core/blob/master/roadmap.md• .NET Foundation – https://dotnetfoundation.org/