Showing posts with label .NET Core. Show all posts
Showing posts with label .NET Core. Show all posts

Wednesday, February 26, 2020

ASP.NET Core Middleware

ASP.NET Core introduced a new concept called Middleware. 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 or short-circuiting the pipeline. When a middleware short-circuits, it's called a terminal middleware because it prevents further middleware from processing the request.
In the classic ASP.NET, HttpHandlers and HttpModules were part of request pipeline. Middleware is similar to HttpHandlers and HttpModules where both needs to be configured and executed in each request.
Typically, there will be multiple middleware in ASP.NET Core web application. It can be either framework provided middleware, added via NuGet or your own custom middleware. We can set the order of middleware execution in the request pipeline. Each middleware adds or modifies http request and optionally passes control to the next middleware component.
1. Use: chain multiple request delegates together. The next parameter represents the next delegate in the pipeline. You can short-circuit the pipeline by not calling the next parameter.
2. Run: delegates don't receive a next parameter. The first Run delegate is always terminal and terminates the pipeline.
3. Map: extensions are used as a convention for branching the pipeline. Map branches the request pipeline based on matches of the given request path. If the request path starts with the given path, the branch is executed.

Tuesday, November 27, 2018

.NET Core 3

.NET Core is a free and open-source managed computer software framework for the Windows, macOS and Linux operating systems. It consists of CoreCLR, a complete runtime implementation of CLR, the virtual machine that manages the execution of .NET programs. CoreCLR comes with an improved just-in-time compiler, called RyuJIT. .NET Core also includes CoreFX, which is a partial fork of FCL. While .NET Core shares a subset of .NET Framework APIs, it comes with its own API that is not part of .NET Framework. Further, .NET Core contains CoreRT, the .NET Native runtime optimized to be integrated into AOT compiled native binaries. A variant of the .NET Core library is used for UWP. .NET Core's command-line interface offers an execution entry point for operating systems and provides developer services like compilation and package management.
.NET Core 3.0 supports for Windows Desktop applications, specifically Windows Forms, Windows Presentation Framework (WPF), and UWP XAML. There are many benefits that .NET Core will bring for desktop applications. Some of them are mentioned below.
  • Performance improvements and other runtime updates
  • Easy to use or test a new version of .NET Core
  • Enables both machine-global and application-local deployment
  • Support for the .NET Core CLI tools and SDK-style projects in Visual Studio
New features in .NET Core 3.0
  • Side-by-side and App-local Deployment: The .NET Core deployment model is one the biggest benefits that Windows desktop developers will experience with .NET Core 3. In short, you can install .NET Core in pretty much any way you want. It comes with a lot of deployment flexibility. Deployment of .NET Core desktop applications can either use a global install of the .NET Core runtime (similar to how .NET Framework is deployed), or side-by-side deployment so that each application uses its own version of the runtime.
  • Easily convert existing Desktop applications to .Net Core 3: The conversion of existing desktop application to .NET Core 3.0 will be pretty straightforward.
  • Improvement to Project Files: The .Net Core has adopted the SDK based project structure as it offers many advantages like:
    • Much smaller and cleaner project files
    • Much friendlier to source control (fewer changes and smaller diffs)
    • Edit project files in Visual Studio without unloading
    • NuGet is part of the build and responsive to changes like target framework update
    • Supports multi-targeting
  • Continue to support Controls, NuGet Packages, and Existing Assembly References: Desktop applications often have many dependencies, maybe from a control vendor, from NuGet or binaries that don’t have a source any more. .NET Core 3.0 will continue to support dependencies as-is without requiring developers to rewrite functionalities.