Skip to main content

Posts

Showing posts with the label ASP.NET Core

ASP.NET Core : Implement a custom middleware component

In ASP.NET Core, a middleware component is a class that implements the IMiddleware interface or is a class that has a method named Invoke or InvokeAsync. To create a custom middleware component, you can create a new class and implement the InvokeAsync method. Here is an example of a custom middleware component that logs the request and response information:       public class RequestResponseLoggingMiddleware     {         private readonly RequestDelegate _next;           public RequestResponseLoggingMiddleware (RequestDelegate next)         {             _next = next;         }           public async Task InvokeAsync(HttpContext context)         {             // Log the request information             var request = context.Request;             Console.WriteLine( $" {request.Method} {request.Path} " );             foreach (var header in request.Headers)              {                 Console.WriteLine( $" {header.Key} : {header.V

ASP.NET Core Advanced Interview Questions - Part -1

  1)          In ASP.NET Core what CreateHostBuilder will do? In Program.cs, this is the very first thing happening in the application, this function will create object for the host and based on the host object the subsequent processes will happen like creating a scope, creating services objects, etc. 2)          What is host in ASP.NET Core? As a first step the ASP.NET Core apps configure and launch a host. The host is responsible for app startup and lifetime management. Ideally, the host configures a server and a request processing pipeline. The host can also set up logging, dependency injection, and configuration. 3)          What is the purpose of Program.cs in ASP.NET Core? This is the entry point of the ASP.NET Core application where the program will build the host object and create scope of the application 4)          What is Scope in ASP.NET Core? In ASP.NET Core, we can create and manage custom scopes by calling CreateScope() when for the need of custom services