Pages

Men

rh

12/28/2022

.Net Core

MSDotnet Stack
The .NET Core platform is a new .NET stack that is optimized for open source development and agile delivery on NuGet. .NET Core has two major components. It includes a small runtime that is built from the same codebase as the .NET Framework CLR.
  • The .NET Core runtime includes the same GC and JIT (RyuJIT), but doesn’t include features like Application Domains or Code Access Security.
  • .NET Core also includes the base class libraries. These libraries are largely the same code as the .NET Framework class libraries, but have been factored (removal of dependencies) to enable to ship a smaller set of libraries. These libraries are shipped as System.* NuGet packages on NuGet.org.
  • 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.
  • 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
  • The SDK is all of the stuff that is needed/makes developing a .NET Core application easier, such as the CLI and a compiler.The runtime is the "virtual machine" that hosts/runs the application and abstracts all the interaction with the base operating system.
    Kestrel is the web server that is included by default in ASP.NET Core new project templates. If your application accepts requests only from an internal network, you can use Kestrel by itself.
    If you expose your application to the Internet, you must use IIS, Nginx, or Apache as a reverse proxy server.
  • A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel after some preliminary handling.
  • The most important reason for using a reverse proxy for edge deployments (exposed to traffic from the Internet) is security. Kestrel is relatively new and does not yet have a full complement of defenses against attacks.
  • NET as whole now has 2 flavors:
  • .NET Framework
  • .NET Core
  • .NET Core and the .NET Framework have (for the most part) a subset-superset relationship. .NET Core is named “Core” since it contains the core features from the .NET Framework, for both the runtime and framework libraries. For example, .NET Core and the .NET Framework share the GC, the JIT and types such as String and List.
  • .NET Core was created so that .NET could be open source, cross platform and be used in more resource-constrained environments.
  • the core features on .Net core:
  • Cross-platform & container support.
  • High performance.
  • Asynchronous via async/await.
  • Unified MVC & Web API frameworks.
  • Multiple environments and development mode.
  • Dependency Injection.
  • WebSockets & SignalR.
  • Cross-Site Request Forgery (CSRF) Protection.
  • Self hosted Web Applications
  • Action Filters
  • Extensible Output Caching
  • Globalization and Localization
  • Swagger OpenAPI
  • Authorization filters
  • Resource filters:
  • OnResourceExecuting
  • OnResourceExecuted
  • Action Filters
  • Exception Filters
  • Result Filters
  • Filters support both synchronous and asynchronous implementations.Aynchronous filters can run code before (On-Stage-Executing) and after (On-Stage-Executed) their pipeline.
  • Global.JSON
  • Appsettings.JSON
  • Project.JSON
  • LaunchingSettings.JSON
  • Bower.JSON
  • Package.JSON
  • Hosting.JSON
  • app.Use may call next middleware component in the pipeline. On the other hand, middlware defined using app.Run will never call subsequent middleware.
    WebListener is also a web server for ASP.NET Core that runs only on Windows. It’s built on the Http.Sys kernel mode driver. WebListener is an alternative to Kestrel that can be used for direct connection to the Internet without relying on IIS as a reverse proxy server.
    ASP.NET Core Module (ANCM) lets you run ASP.NET Core applications behind IIS and it works only with Kestrel; it isn’t compatible with WebListener. ANCM is a native IIS module that hooks into the IIS pipeline and redirects traffic to the backend ASP.NET Core application. ASP.NET Core applications run in a process separate from the IIS worker process,ANCM also does process management. ANCM starts the process for the ASP.NET Core application when the first request comes in and restarts it when it crashes. In short, it sits in IIS and routes the request for ASP.NET Core application to Kestral.
    The host is responsible for application startup and lifetime management.Other responsibility of host’s includes ensuring the application’s services and the server are available and properly configured. The host is typically created using an instance of a WebHostBuilder, which builds and returns a WebHost instance.
    Asynchronous programming is a means of parallel programming in which a unit of work runs separately from the main application thread and notifies the calling thread of its completion, failure or progress.
    In simpler terms: Synchronous execution means the execution happens in a single series.
    A->B->C->D. If you are calling those routines, A will run, then finish, then B will start, then finish,then C will start, etc.
    With Asynchronous execution, you begin a routine, and let it run in the background while you start your next, then at some point, say "wait for this to finish". It's more like: Start A->B->C->D->Wait for A to finish
    If you use this Async modifier on a method or expression, it's referred to as an async method. An async method runs synchronously until it reaches its first await expression, at which point the method is suspended until the awaited task is complete.
    If the method that the async keyword modifies doesn't contain an await expression or statement, the method executes synchronously. A compiler warning alerts you to any async methods that don't contain await statements, because that situation might indicate an error.
  • Open-source and community-focused.
  • Ability to develop and run on Windows, macOS, and Linux.
  • Built-in dependency injection.
  • Ability to host on IIS, Nginx, Apache, Docker, or self-host in your own process.
  • A lightweight, high-performance, and modular HTTP request pipeline.
  • A unified story for building web UI and web APIs.
  • Architected for testability.
  • Integration of modern, client-side frameworks and development workflows.
  • A cloud-ready, environment-based configuration system.
  • Side-by-side app versioning when targeting .NET Core.
  • Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:
    Chooses whether to pass the request to the next component in the pipeline.Can perform work before and after the next component in the pipeline.
    Request delegates are used to build the request pipeline. The request delegates handle each HTTP request.
    Request delegates are configured using Run, Map, and Use extension methods. An individual request delegate can be specified in-line as an anonymous method (called in-line middleware), or it can be defined in a reusable class.
    These reusable classes and in-line anonymous methods are middleware, also called middleware components. Each middleware component in the request pipeline is responsible for invoking the next component in the pipeline.
    Create a middleware pipeline with IApplicationBuilder : The ASP.NET Core request pipeline consists of a sequence of request delegates, called one after the other.
    Each delegate can perform operations before and after the next delegate. Exception-handling delegates should be called early in the pipeline, so they can catch exceptions that occur in later stages of the pipeline.
    The simplest possible ASP.NET Core app sets up a single request delegate that handles all requests. This case doesn't include an actual request pipeline. Instead, a single anonymous function is called in response to every HTTP request.
    public class Startup { public void Configure(IApplicationBuilder app) { app.Run(async context => { await context.Response.WriteAsync("Hello, World!"); }); } }
    In particular, HTTP/1.0 allowed only one request to be outstanding at a time on a given TCP connection. HTTP/1.1 added request pipelining, but this only partially addressed request concurrency and still suffers from head-of-line blocking.
    Therefore, HTTP/1.0 and HTTP/1.1 clients that need to make many requests use multiple connections to a server in order to achieve concurrency and thereby reduce latency.
    HTTP/2 addresses these issues by defining an optimized mapping of HTTP's semantics to an underlying connection. Specifically, it allows interleaving of request and response messages on the same connection and uses an efficient coding for HTTP header fields. It also allows prioritization of requests, letting more important requests complete more quickly, further improving performance.
  • Hypertext Transfer Protocol (HTTP), referred to as HTTP version 2 (HTTP/2).
  • HTTP/2 enables a more efficient use of network resources and a reduced perception of latency by introducing header field compression and allowing multiple concurrent exchanges on the same connection.
  • Endpoint Routing is a new feature from Asp.Net Core 2.2 and above versions. To consume Endpoint routing we need to configure two middlewares.
  • UseRouting
  • UseEndpoints
  • UseRouting : this middleware should be configured before any other middlewares like authentication, authorization or custom middlewares. UseRouting middleware populates the current Httpcontext with route values, controller metadata ( which is not available in the previous version like Asp.net 2.1 or above versions). So any middleware after the UseRouting middleware has the capability to access route values or MVC controller metadata.
    UseEndpoints : this middleware should be configured at last in the application. UseEndpoints consist of all conventional based URL's. UseEndpoints is a delegate that executes the route and returns the response.
    Example :
    app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "testRoute", pattern: "test/{actionName}", defaults: new { controller = "Test", action = "index" }); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); });
    1) Windows Desktop Apps Explanation: The highlight of .NET Core 3 is support for Windows desktop applications, specifically Windows Forms, Windows Presentation Framework (WPF), and UWP XAML. You will be able to run new and existing Windows desktop applications on .NET Core
    2) Language improvements C# 8.0
    3) .NET Standard 2.1 Explanation: .NET Core 3.0 implements .NET Standard 2.1. However, the default dotnet new classlib template generates a project that still targets .NET Standard 2.0. To target .NET Standard 2.1.
    4) Blazor Server Explanation: With .NET Core 3.0, you can develop amazing interactive client-side UI with Blazor Server. Blazor Server can be used to write completely new apps or to complement existing MVC and Razor Pages apps. There’s no need to rewrite existing app logic. Blazor is designed to work together with MVC and Razor Pages, not to replace them. You can continue to use MVC and Razor Pages for your server-rendering needs while using Blazor for client-side UI interactions.
    Blazor Server is a great way to add client-side functionality to your existing and new web apps using your existing .NET skills and assets. Blazor Server is built to scale for all your web app needs. Blazor WebAssembly is still in preview but is expected to ship in May of next year. In the future, it is expected to continue to evolve Blazor to support PWAs, hybrid apps, and native apps. For now, we hope you’ll give Blazor Server a try by installing .NET Core 3.0.
    5) Windows desktop: Explanation: NET Core 3.0 supports Windows desktop applications using Windows Presentation Foundation (WPF) and Windows Forms. These frameworks also support using modern controls and Fluent styling from the Windows UI XAML Library (WinUI) via XAML islands. The Windows Desktop component is part of the Windows .NET Core 3.0 SDK. You can create a new WPF or Windows Forms app with the following dotnet commands: .NET Core CLI
  • dotnet new wpf
  • dotnet new winforms
  • 6) SerialPort for Linux: Explanation: .NET Core 3.0 provides basic support for System.IO.Ports.SerialPort on Linux. Previously, .NET Core only supported using SerialPort on Windows.
    7) Fast built-in JSON support Explanation: The new built-in JSON support is high-performance, low allocation, and based on Span.
    8) Cryptography ciphers Explanation: .NET 3.0 adds support for AES-GCM and AES-CCM ciphers, implemented with System.Security.Cryptography.AesGcm and System.Security.Cryptography.AesCcm respectively. These algorithms are both Authenticated Encryption with Association Data (AEAD) algorithms.
    1) It supports partial class for Razor components
    2) It passes parameters to top-level components
    3) It supports new component tag helper
    4) It prevents default actions for events in Blazor application
    5) It stops event propagation in Blazor application
    6) It gives detailed errors during Blazor application development
    7) It supports shared queues in HttpSysServer
    8) It has breaking changes for SameSite cookies
    9) It Support Different Operating Systems :
  • openSUSE: 15+
  • RHEL: 6+
  • Debian: 9+
  • Alpine: 3.10+
  • Ubuntu: 16.04+
  • Fedora: 29+
  • SUSE Enterprise Linux (SLES): 12 SP2+
  • macOS: 10.13+
  • Windows Server: 2012 R2+
  • Windows Client: 7, 8.1, 10 (1607+)
  • 10)The .NET Core 3.1 has removed the Win Forms controls such as:##
  • DataGrid
  • ContextMenu
  • Toolbar
  • Menu
  • MainMenu
  • 11) Chip Support
  • x86 on Windows
  • x64 on Windows, Linux, and macOS
  • ARM64 on Linux (Use Linux kernel version 4.14 or later)
  • ARM32 on Windows and Linux
  • Meaning: The fact that it's an interface is irrelevant. Applying the readonly modifier on a field prevents you (or someone else)to change its value after the object is constructed. It can only be assigned in the constructor.
    A readonly field means it can only be written in the ctor. Once that's completed, the reference can't be changed or destroyed. It's very useful for initializing state and enforcing immutability.
    The advantage of having readonly on the field is it's a clear declaration that the field will not change during the lifetime of the containing instance.
    All source collected from https://learn.microsoft.com/en-us/ef/core/

    No comments :

    Post a Comment