Skip to main content

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 that live outside of a HttpRequest, the interface used for this is IServiceProvider

5)         What is Startup class?

This is the 2nd thing called after the Program.cs in the ASP.NET Core application, now Startup.cs file is not present from version 6.0

6)         What are ConfigureServices and Configure methods?

Both the methods were present until version 5.0 and no longer present from the version 6.0,

Configure Services method:  This method gets called by the runtime. Use this method to add services to the container.

Example: 

Configure method: This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Example:


 

 

As mentioned earlier from version 6.0 we don’t have the Startup.cs file, all the configurationservices and configure items has been moved to Program.cs and there will be no dedicated method to categorize the both, programmers will use with comments like this.

7)         What is the process in Request Pipeline?

8)         While creating services how will you determine the lifetime and scope of the objects and how can you specify this?

There are 3 ways to create the services objects and set the scope of them

a)         Transient: Creates fresh new objects for every request, example: A new sale order object, new employee object

b)         Scoped: These will be same for each request or session, but different for different sessions, say for example user session details will be provided in a single object for a given user and a different user session object will be built for another user

c)          Singleton: Only one object will be created throughout the application (not user specific), example: making log entries of the application requires only single object for the application lifetime.

9)         What is the difference between IOC and DI?

IOC (Inversion of control) is the design target intended to achieve between the classes and their dependencies

 

DI (Dependency Injection) is one of the design patterns used to achieve this target

 

There are other ways to achieve IOC which is subjected to the application

 

As the name suggests the flow of controls is inverted to improve the performance, maintainability and scalability.

 

10)  What is the difference between app.run and app.use

Both will do the task of adding the middleware to the request pipeline, but the basic difference is app.run will terminate the request and does not process the further requests

 

Where as the app.use will add the middleware to the request pipeline and transfer the process to the next middleware.

Comments

Popular posts from this blog

Task Parallel Library (TPL) and Akka.NET: Differences

Task Parallel Library (TPL) and Akka.NET are both powerful tools in the .NET ecosystem for handling parallelism and concurrency, but they serve different purposes and use different models of computation. Here are some key differences:s 1.    Actor Model vs Task-Based Model: Akka.NET is built around the actor model, where actors are the fundamental units of computation and they communicate by exchanging messages. TPL, on the other hand, is task-based. It's designed to make developers more productive by simplifying the process of adding parallelism and concurrency to applications. TPL uses tasks (which are independently executing work units) and provides various ways to control and coordinate them. 2.    Fault Tolerance: One of the key features of Akka.NET is its built-in fault tolerance. It has a "let-it-crash" philosophy, where the system is designed to self-heal from errors. If an actor fails, its parent actor can decide on the supervision strategy: either to resta

Extension Methods - Advanced

Here we will see how can we use the Extension Methods in advanced manner in other types Imagine you often need to retrieve items from a List based on a custom criterion that the built-in LINQ methods don't cover. Extension Methods for Lists: Filtering based on Custom Criteria And the output would be   Extending Enums: Displaying Descriptive Strings Output: Extending DateTime: Calculating Age     Output: The code samples can be found at https://github.com/oneananda/C_Sharp_Examples/tree/main/ExtensionMethods