1 - What is the MVC pattern?


MVC (Model-View-Model) is a design pattern used to decouple user-interface (view), data (model), and application logic (controller). This pattern helps to achieve separation of concerns. 

Using the MVC pattern for websites, requests are routed to a Controller which is responsible for working with the Model to perform actions and/or retrieve data. The Controller chooses the View to display, and provides it with the Model. The View renders the final page, based on the data in the Model.

2 - What is the "startup" class in ASP.NET core?


The "startup" class is the entry point of the ASP.NET Core application. This class contains the application configuration.

This class contains two main methods: 

  • ConfigureServices - It's used to configure the services that are used by the application. Using this method, we can add the services to the DI container.
  • Configure - It defines how the application will respond to each HTTP request. We can configure the request pipeline by configuring the middleware, such as routing, authentication, session, etc...

3 - What is Razor Pages?


Razor Pages are simple pages or views without controllers and introduced with the intent of creating page focused scenarios where there is no real logic is involved. It is similar to ASP.NET Web Forms.

The difference between Razor Views and Razor Pages is the @page directive. Which makes the file into an MVC action. So, it handles requests directly, without going through a controller.

4 - What are the different Validators in ASP.NET?


ASP.NET validation define an important role in validating the user input data. Whenever the user gives input, it must always be validated before sending it across the various layers of an application. 

There are two types of validations:

  • Client Side ValidationWhen validation is done on the client browser. For example: using javascript. This kind of validation can catch basic errors before sending the requests to the server.
  • Server Side ValidationWhen validation occurs on the server. This validation cannot be bypassed like in client side validation.

5 - How dependency injection works in ASP .NET Core?


ASP.NET Core allows us to specify the lifetime for registered services. The service instance gets disposed of automatically based on a specified lifetime.

  • SingletonASP.NET Core will create and share a single instance of the service through the application life. 

  • TransientASP.NET Core will create and share an instance of the service every time to the application when we ask for it. 

  • ScopedASP.NET Core will create and share an instance of the service per request to the application. It means that a single instance of service available per request.

6 - What is asynchronous actions?


Asynchronous actions won’t block the executing thread if it waits for an I/O operation. Using asynchronous actions can increase the throughput of a system if you use such a pattern for I/O operations, but it won’t help with CPU-bound operations.

7 - What should be the lifetime for a database connection/ORM context in an ASP.NET MVC application?


The lifetime should be the same as the request, because usually requests don’t live very long. Where it’s possible to wrap the whole request in one transaction, this can help comply with ACID principles.

8 - What is Kestrel?


Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included by default in ASP.NET Core project templates. The transport layer is based on managed sockets which makes Kestrel super fast.

9 - What is the Generic Host?


A generic host is an object that encapsulates an application resources, such as: logging, dependency injection, configuration, services. 

When a host starts, it calls IHostedService.StartAsync on each implementation of IHostedService that it finds in the DI container. For example: if we are running a web application then the host will start an http server.