ASP NET CORE Ivan Davydko NET Developer Data

  • Slides: 32
Download presentation
ASP. NET CORE ИСПЫТАНИЕ БОЕМ Ivan Davydko. NET Developer, Data. Art

ASP. NET CORE ИСПЫТАНИЕ БОЕМ Ivan Davydko. NET Developer, Data. Art

Introduction 26 October 2020 3

Introduction 26 October 2020 3

Question 26 October 2020 4

Question 26 October 2020 4

ASP. NET 5 is dead – Introducing ASP. NET Core 1. 0 and. NET

ASP. NET 5 is dead – Introducing ASP. NET Core 1. 0 and. NET Core 1. 0 There are only two hard things in Computer Science: cache invalidation and naming things. - Phil Karlton ASP. NET 5 > ASP. NET v. Next > Project K > ASP. NET Core 1. 0 REINTRODUCING ASP. NET CORE 1. 0 AND. NET CORE 1. 0 • ASP. NET 5 is now ASP. NET Core 1. 0. • . NET Core 5 is now. NET Core 1. 0. 26 October 2020 • Entity Framework 7 is now Entity Framework Core 1. 0 or EF Core 1. 0 colloquially. 5

Introduction to ASP. NET Core is a significant redesign of ASP. NET Core is

Introduction to ASP. NET Core is a significant redesign of ASP. NET Core is a new open-source and cross-platform framework for building modern cloud based internet connected applications, such as web apps, Io. T apps and mobile backends. ASP. NET Core apps can run on. NET Core or on the full. NET Framework. It was architected to provide an optimized development framework for apps that are deployed to the cloud or run on-premises. You can develop and run your ASP. NET Core apps cross-platform on Windows, Mac and Linux. ASP. NET Core is open source at Git. Hub. 26 October 2020

Question 26 October 2020 7

Question 26 October 2020 7

Choosing between. NET Core and . NET Framework for server apps. NET Core .

Choosing between. NET Core and . NET Framework for server apps. NET Core . NET Framework • You have cross-platform needs. • You are using Docker containers. • Your application currently uses. NET Framework (recommendation is to extend instead of migrating) • You need high performance and scalable systems. • You need to use third-party. NET libraries or Nu. Get packages not available for. NET Core. • You need side by side of. NET versions by application. • You need to use. NET technologies that are not available for. NET Core. • You are targeting microservices. • You need to use a platform that doesn’t support . NET Core. 26 October 2020 8

Fundamentals 26 October 2020 9

Fundamentals 26 October 2020 9

Fundamentals • ASP. NET Core app is simply a console app • ASP. NET

Fundamentals • ASP. NET Core app is simply a console app • ASP. NET Core doen’t use System. Web library. • Mainly uses Kestrel web server. Can use Web. Listeners. • In ASP. NET Core you compose your request pipeline using Middleware. You can use any OWIN-based middleware with ASP. NET Core, and you can write your own custom middleware. • New configuration model. Supports XML, JSON, INI and environment variables. • . NET Core vs. . NET Framework runtime. An ASP. NET Core app can use the. NET Core or . NET Framework runtime. 26 October 2020

Kestrel 26 October 2020

Kestrel 26 October 2020

Web. Listener 26 October 2020

Web. Listener 26 October 2020

Structure of the Application Content root The content root is the base path to

Structure of the Application Content root The content root is the base path to any content used by the app, such as its views and web content. By default the content root is the same as application base path for the executable hosting the app. 26 October 2020 Web root The web root of your app is the directory in your project for public, static resources like css, js, and image files. The static files middleware will only serve files from the web root directory (and sub-directories) by default. The web root path defaults to /wwwroot.

CSProj File Improvements 1. Format and Size. The csproj file format has been significantly

CSProj File Improvements 1. Format and Size. The csproj file format has been significantly simplified to make it more friendly for the command line experience. 1. 2. 3. Supports a wildcard syntax, to avoid the need of listing individual source files. Provides you with access to all of the assemblies, tools and targets that are part of the. NET Core runtime install and. NET Core SDK. Avoids the use of complex values such as GUIDs 2. Ability to add Nu. Get packages within the csproj format, instead of needing to specify them in a separate file with a special format. 3. Editing CSProj files. You can now edit CSProj files, while the project is open and with intellisense. It also does a good job of showing the similarily between Nu. Get and projects references. 26 October 2020

Strongly Typed Configurations // POCO class public class My. Settings { public string Application.

Strongly Typed Configurations // POCO class public class My. Settings { public string Application. Name { get; set; } public int Max. Items. Per. List { get; set; } } // Add our Config object to Dependency Injecton so it can be injected public void Configure. Services(IService. Collection services) { Add our Config object so it can be injected services. Configure<My. Settings>(Configuration. Get. Section("My. Settings")); } // Part of the JSON in appsettings. json { "My. Settings": { "Application. Name": "My Very First MVC Application", "Max. Items. Per. List": 10 } } // Inject the configuration data into the controller 26 October 2020 public Controller(IOptions<My. Settings> settings) { My. Settings = settings. Value; }

Working samples and crutches 26 October 2020 17

Working samples and crutches 26 October 2020 17

Implement Mail notifications. NET Framework contains System. Net. Mail library for this purposes. In.

Implement Mail notifications. NET Framework contains System. Net. Mail library for this purposes. In. NET Core System. Net. Mail is NOT available (there is a prerelease version System. Net. Mail-netcore 1. 0. 0 -rtm-00002). As alternative we can use Mail. Kit (a cross-platform mail client library built on top of Mime. Kit). ASP. NET Core team is not planning to port System. Net. Mail to . NET Core. “Its not in our current plans but the code is available here if you are interested in porting it to make it work. dopare closed this on Feb 25, 2015”. So you’re welcome to do it by yourself 26 October 2020 18

26 October 2020 19

26 October 2020 19

Work with Active Directory. NET Framework contains System. Directory. Services library for this purposes.

Work with Active Directory. NET Framework contains System. Directory. Services library for this purposes. In. NET Core System. Directory. Services is NOT available. Issue #2089 “Support for System. Directory. Services” in Git. Hub. It is planned to be ported in future. According to the milestones list it will NOT be in 1. 1. x release. For now you can try to work with Novell. LDAP library, which is ported to. NET Core. 26 October 2020 20

26 October 2020 21

26 October 2020 21

Implement In-Memory Caching ASP. NET Core supports several different caches. We decided to use

Implement In-Memory Caching ASP. NET Core supports several different caches. We decided to use IMemory. Cache interface, which represents a cache stored in the memory of the web server. Methods summary • Create. Entry(Object) • Remove(Object) • Try. Get. Value(Object, out Object) Extensions methods summary Get(IMemory. Cache, Object) Get. Or. Create<TItem>(IMemory. Cache, Object, Func<ICache. Entry, TItem>) Get. Or. Create. Async<TItem>(IMemory. Cache, Object, Func<ICache. Entry, Task<TItem>>) Set<TItem>(IMemory. Cache, Object, TItem, Memory. Cache. Entry. Options) 26 October 2020 Try. Get. Value<TItem>(IMemory. Cache, Object, out TItem) 22

26 October 2020 23

26 October 2020 23

Caching results Caching result indicator [Cache. Result] The following code cache data var key

Caching results Caching result indicator [Cache. Result] The following code cache data var key = typeof(TQuery). Name; return await _cache. Get. Or. Create. Async(key, entry => { _logger. Log. Information(Messages. No. Cache. Entry, key); entry. Set. Sliding. Expiration(Time. Span. From. Days(1)); return _decorated. Handle. Async(query); }); 26 October 2020 24

Updating cached result [Reset. Cache. For(typeof(Get. Foos))] var attribute = command. Get. Type(). Get.

Updating cached result [Reset. Cache. For(typeof(Get. Foos))] var attribute = command. Get. Type(). Get. Type. Info() . Get. Custom. Attributes<Reset. Cache. For. Attribute>() . First. Or. Default(); foreach (var type in attribute. Types) { var key = type. Name; _cache. Remove(key); dynamic query = Activator. Create. Instance(type, new object[]{null}); await _query. Runner. Run. Query. Async((dynamic)query); _logger. Log. Information(Messages. Cache. Entry. Refreshed, key); 26 October 2020 } 25

Benchmarks 26 October 2020 26

Benchmarks 26 October 2020 26

Benchmarks Round 13 is especially notable for us because we are honored that Microsoft

Benchmarks Round 13 is especially notable for us because we are honored that Microsoft has made it a priority to improve ASP. NET’s performance in these benchmarks, and in so doing, improve the performance of all applications built on ASP. NET. The degree of improvement is absolutely astonishing, going from 2, 120 requests per second on Mono in Round 11 to 1, 822, 366 requests per second on ASP. NET Core in Round 13. That’s an approximately 85, 900% improvement, it's 859 times faster. November 16, 2016. https: //www. techempower. com/blog/2016/11/16/framework-benchmarks-round 13/ 26 October 2020 27

ASP. NET Core – Exceeds 1. 15 Million request/s, 12. 6 Gbps 26 October

ASP. NET Core – Exceeds 1. 15 Million request/s, 12. 6 Gbps 26 October 2020 28

Stack Server Node. JS Benchmarks perfsvr 147, 554 Node. JS ASP. NET Core on

Stack Server Node. JS Benchmarks perfsvr 147, 554 Node. JS ASP. NET Core on Kestrel perfsvr 2 (Linux) perfsvr ASP. NET Core on perfsvr 2 (Linux) Kestrel Scala perfsvr Req/sec Load Params Impl Observations 32 threads, 256 connections The actual Tech. Empower Node. JS app CPU is 100%, almost exclusively in user mode 173, 641 32 threads, 512 connections The actual Tech. Empower Node. JS app CPU is 100% 1, 174, 881 32 threads, 256 connections Middleware class, multi IO thread CPU is 100% 928, 023 32 threads, 256 connections Middleware class, single IO thread 1, 514, 942 26 October 2020 Netty perfsvr 2, 808, 515 The actual 32 threads, 1024 Tech. Empower connections Scala plaintext app The actual 32 threads, 256 Tech. Empower connections Netty app CPU is 100%, 70% in user mode 29 CPU is 100%

Thanks to ASP. NET Core team 26 October 2020

Thanks to ASP. NET Core team 26 October 2020

Thanks 26 October 2020 31

Thanks 26 October 2020 31

Question to the audience What is the difference between. NET Core, . NET Standard

Question to the audience What is the difference between. NET Core, . NET Standard and. NET Framework? 26 October 2020