46  
netcore
Advertisement
Поиск  
Always will be ready notify the world about expectations as easy as possible: job change page
месяц назад

Top asked .NET Core interview questions & answers

Top asked .NET Core interview questions & answers
Автор:
Источник:
Просмотров:
295

These interview questions range from basic to advanced .Net Core, and will assist you in preparing for interviews, revising quickly, and strengthening your technical skills.

According to the Stackoverflow Survey 2020,.NET and.NET Core are the second and third most popular frameworks and libraries, respectively. It is frequently the first programming language that programmers learn after understanding OOPs ideas. A variety of factors contribute to the success, NET’s one of which is the stack-layered design. You may add/update layers without affecting the rest of the program thanks to this architecture. .NET can be used to create a variety of high-performance applications, such as gaming applications. Console apps, GUI apps, internet apps, web API apps, Windows services, and other programs benefit from improved monitoring, scalability, performance, and consistency.

.NET MVC (Model-View-Controller) introduces a flood of new features to aid in the development of modular applications. It allows component-based development and testing, which streamlines the entire application development and testing process.

1. What are the advantages of .NET Core?

ASP.NET Core is not an improved version of the ASP.NET framework. With ASP.NET Core, all work with the.NET Core foundation is completely redone. It’s more faster, more versatile, modular, scalable, expandable, and cross-platform compatible. It can work with both.NET Core and.NET Framework thanks to the.NET standard framework. It’s perfect for creating cloud-based apps including web apps, smartphone apps, and Internet of Things apps.

2. What are the features provided by ASP.NET Core?

  • Support for Dependency Injection is built-in.
  • The logging framework has built-in support and can be extended.
  • Kestrel, a new fast and cross-platform web server, has been released. As a result, a web application can be run without the use of IIS, Apache, or Nginx.
  • A variety of hosting options are available.
  • Because it allows modularity, the developer must include the module that the application requires. The.NET Core framework, on the other hand, offers a meta package that includes the libraries.
  • The application can be created, built, and run from the command line.
  • There isn’t a web.config file to be found. The custom configuration can be saved in an appsettings.json file.
  • There is no file named Global.asax. We can now register for and use the starter class services.
  • It provides good asynchronous programming support.

3. What is Kestrel?

Kestrel is a.NET application server that is event-driven, I/O-based, open-source, cross-platform, and asynchronous. Because it is the default server for .NET Core, it is compatible with all of the platforms and versions that.NET Core supports.

It is typically used as an edge-server, which means it is the server that is exposed to the internet and directly handles HTTP web requests from clients. It’s a command-line interface for a listening server.

Kestrel

4. What is metapackages?

Metapackage is a feature of the.NET Core 2.0 framework that combines all of the packages supported by ASP.NET code, as well as their dependencies, into a single package. We can create faster because we don’t have to include the different ASP.NET Core packages. The meta package Microsoft.AspNetCore.All is provided by ASP.NET core.

5. What is middleware?

All requests and responses must pass via middleware, which is a layer, software, or simple class. In an application pipeline, the middleware is made up of numerous delegates. Each component (delegate) in the middleware’s pipeline makes the following decision:

Passing the request on to the next component.
Before or after passing the request, perform some processing on it.
The figure below depicts a middleware request pipeline with several delegates that are invoked one after the other. The direction of execution is indicated by black arrows. Before or after the next delegate, each delegate in the diagram conducts certain tasks.

Middleware

6. The usage of Startup.cs

The ASP.NET Core application’s entry point is the Startup class. This class is required in every.NET Core application. This class holds items relevant to application configuration. It is not required that the class name be “Startup,” as we can configure the startup class in the Program class.

Startup.cs

7. What are the service lifetimes

The ASP.NET Core application’s entry point is the Startup class. This class is required in every.NET Core application. This class holds items relevant to application configuration. It is not required that the class name be “Startup,” as we can configure the startup class in the Program class.

  • Transient Service: When we ask for it, ASP.NET Core will construct and share an instance of the service with the application. IServiceCollection’s AddTransient function can be used to add the service as a Transient. This lifespan is suitable for stateless service. It’s a way to add a simple service.
  • Scoped Service: Per request to the application, ASP.NET Core will construct and distribute an instance of the service. It indicates that each request is served by a single instance of the service. In the new request, it will create a new instance. IServiceCollection’s AddScoped function can be used to add the service as scoped. We must exercise caution while injecting a service registered via Scoped in middleware into the Invoke or InvokeAsync methods. It operates like a singleton object when we inject dependencies via the builder.
  • Singleton Service: Throughout the application’s lifecycle, ASP.NET Core will generate and distribute a single instance of the service. The AddSingleton function of IServiceCollection can be used to add the service as a singleton. At the time of registration, ASP.NET Core creates a service instance, which is used by subsequent requests. We don’t need to use the Singleton design pattern because ASP.NET Core maintains a single instance for us.

Service lifetimes

8. What is the use of ConfigureServices method of startup class?

This is a starter class method that is optional. It can be used to set up the services that the application uses. When the application is first requested, this method is called first. We may add services to the DI container using this technique, making them available as a dependency in the controller builder.

9. What is the use of the Configure method of startup class?

It specifies how each HTTP request will be handled by the programme. By customising the middleware, we may customise the request pipeline. It has two optional parameters: IHostingEnvironment and ILoggerFactory, as well as accepting IApplicationBuilder as a parameter. We can configure built-in middleware like routeing, authentication, and sessions, as well as third-party middleware, using this way.

10. What are the Advantages of .NET Core over .NET Framework?

  • It is cross-platform, meaning it can be used on Windows, Linux, and Mac computers.
  • Because all of the needed dependencies are included with our application, there is no need to install a framework.
  • ASP.NET Core is capable of handling more requests than ASP.NET.
  • With ASP.NET Core, you have a variety of deployment options.

11. The difference between IApplicationBuilder.Use() and IApplicationBuilder.Run()?

Both approaches can be used in the Startup class’s Configure methods. Both are used to add a middleware delegate to the request pipeline of an application. IApplicationBuilder is used by the middleware to add applications. While the middleware adds using IApplicationBuilder, we can call the following middleware in the pipeline. The Run method never calls the next or subsequent middleware. The system stops adding middleware to the request pipeline after the IApplicationBuilder.Run method is called.

12. What is response caching in .NET Core?

Cache-related headers are mentioned in the HTTP replies of.NET Core MVC activities during response caching. We can describe how the client/proxy machine will cache responses to queries using these headers. Because the responses are sent from the cache, the number of client/proxy requests to the web server is reduced.

The first request, as shown in the diagram below, goes through a full cycle from client browser to proxy server and finally to web server. The response has now been cached by the proxy server. The proxy server provides the response from the cache for all subsequent requests. As a result, there are fewer proxy/client requests to the web server.

Response caching

13. What is a generic host in .NET Core?

In.NET Core for web applications, the generic host was previously known as ‘Web Host.’ Later, the term ‘Web Host’ was dropped in favour of a generic host that could handle web, Windows, Linux, and console applications.

We must pay attention to the following points whenever a new application is launched:

  • Dependency Injection
  • Configuration
  • Logging
  • Service lifetime management

Because it is based on the original abstraction of these tools, the.NET generic host ‘HostBuilder’ assists us in managing all of the above chores.

14. What is the use of “Map” extension while adding middleware to ASP.NET Core pipeline?

It is used in the branching of the pipeline. The ASP.NET Core pipeline is branched using request path matching. The middleware on that branch will run if the request path starts with the specified path.

App Map extension

15. What is routing in .NET Core?

It’s the procedure for mapping incoming requests to the appropriate controllers and actions. This task is handled by the routeing middleware in.NET Core MVC. The incoming HTTP requests are matched to the executable request-handling code by this middleware. In the ‘Startup.Configure’ file, we may define the middleware pipeline routeing.

Routing employs routes to map incoming requests to a route handler and generate a response URL. Typically, an application will have a single collection of routes, which will be utilised to process the request. The RouteAsync function maps incoming requests (that match the URL) to routes that are currently accessible in the route collection.

There are two types of supported routings:

  • Conventional routing
  • Attribute routing

16. What is Dependency Injection in .NET Core?

Dependency Injection (DI) is supported by.NET Core, which means the programme is loosely connected. It’s a method for implementing Inversion Control (IoC) between classes and their dependents. In other words, the object simply keeps track of the dependencies that are required for the task at hand. Dependency injection improves the testability, maintainability, and reusability of an application by injecting dependencies into it.

17. How to enable Session in ASP.NET Core?

The package Microsoft.AspNetCore.Session provides the session’s middleware. We must add this package to the csproj file and the Session middleware to the ASP.NET Core request pipeline to use the session in an ASP.NET Core application.

Session in ASP.NET Core

18. What is Request delegate?

To create request pipelines and process each HTTP request, request delegates are used. It can be customised using the Run, Map, and Use extension methods. As a request delegate, you can use an anonymous method (also known as in-line middleware) or a reusable class. These classes or in-line methods are middleware components.

19. What is the Options Pattern in ASP.NET Core?

.NET | Working With Options Pattern: Another way to read data from the configuration data 

20. How to Load Environment Specific Configuration?

How .NET Load Environment Specific Configuration: Now, many times the developers need to work in different environments, such as schema, staging, release, QA.

Summary

I hope you find these questions and answers useful in your ASP.NET Core interview.

Похожее
Dec 20, 2023
Author: Fiodar Sazanavets
You can run a single monolithic instance of a server application only if the number of clients accessing your application doesn’t exceed a couple of thousand. But what if you expect hundreds of thousands, or even millions, of clients to...
Feb 15
Author: Pranaya Rout
Kestrel Web Server in ASP.NET Core ApplicationIn this article, I will discuss the Kestrel Web Server in ASP.NET Core application with examples. Please read our previous article discussing the ASP.NET Core InProcess Hosting Model with examples. At the end of...
Mar 16
Author: Winds Of Change
Performance is paramount when developing web applications. A slow, unresponsive application results in poor user experience, losing users, and possibly business. For ASP.NET Core developers, there are many techniques and best practices to optimize application performance. Let’s explore some of...
Feb 29
Author: Sharmila Subbiah
IntroductionWith the release of .NET 8, Microsoft takes a significant stride forward, introducing the native Ahead-of-Time (AOT) compilation for ASP.NET Core. This advancement not only enhances application performance but also simplifies the development process, marking a new era in the...
Написать сообщение
Почта
Имя
*Сообщение


© 1999–2024 WebDynamics
1980–... Sergey Drozdov
Area of interests: .NET Framework | .NET Core | C# | ASP.NET | Windows Forms | WPF | HTML5 | CSS3 | jQuery | AJAX | Angular | React | MS SQL Server | Transact-SQL | ADO.NET | Entity Framework | IIS | OOP | OOA | OOD | WCF | WPF | MSMQ | MVC | MVP | MVVM | Design Patterns | Enterprise Architecture | Scrum | Kanban