Net Core Interview
Net Core Interview
Net Core Interview
"Dependency Injection" :
ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for
achieving Inversion of Control (IoC) between classes and their dependencies
DI help us to create application which loosely coupled. This means that object should only have those
dependency that required during complete task. The main advantages of DI (Dependency Injection) is
our application loosely coupled and has provide greater maintainability, testability and also re-usability.
It is loosely coupled because dependency required by the class are injected from outer world rather
than created them self directly win-in code.
"Repository;"
The Repository Design Pattern in C# Mediates between the domain and the data mapping layers using a
collection-like interface for accessing the domain objects. In other words, we can say that a Repository
Design Pattern acts as a middleman or middle layer between the rest of the application and the data
access logic.
Transient :Transient objects are always different; a new instance is provided to every controller and
every service.
Scoped : Scoped objects are the same within a request, but different across different requests.
Singleton: Singleton objects are the same for every object and every request.
What is Kestral?
Kestrel is a cross-platform web server for ASP.NET Core based on libuv, a cross-platform asynchronous
I/O library. Kestrel is the web server that is included by default in ASP.NET Core new project templates. If
your application accepts requests only from an internal network, you can use Kestrel by itself.
services.AddSession();
services.AddMvc();
app.UseSession();
….
….
JWT Token: JWT (JSON web token) has become more and more popular in web development. It is an
open standard which allows transmitting data between parties as a JSON object in a secure and
compact way. The data transmitting using JWT between parties are digitally signed so that it can be
easily verified and trusted.
SOLID Principles
There are five SOLID principles:
1. Single Responsibility Principle (SRP)
2. Open Closed Principle (OCP)
3. Liskov Substitution Principle (LSP)
4. Interface Segregation Principle (ISP)
5. Dependency Inversion Principle (DIP)
Single Responsibility Principle (SRP)
Definition: A class should have only one reason to change.
DbContext
The DbContext class is an integral part of Entity Framework. An instance of DbContext
represents a session with the database which can be used to query and save instances of
your entities to a database. DbContext is a combination of the Unit Of Work and Repository
patterns.
….
….
services.AddSession();
services.AddMvc();
….
….
app.UseSession();
….
….
}
}
Advantages of Microservices
Services can be written in different programming language and
can be accessed by using any framework.
Independently develop, deploy, redeploy, version and scale
component services in seconds without compromising the
integrity of an application
Better fault isolation keeps other services to work even though
on got failed.
Zero downtime upgrades.
Services can be of from different servers or even different
datacenters.
Interaction with other services in a well-defined protocol
Monitor, capture, and report health diagnostics
Reliable and self-healing
Supports continuous integration and delivery
Easy to transfer knowledge to the new team member
Easy to integrate with third parties
Disadvantages of Microservices
The additional complexity for implementation of an inter-
process communication mechanism between services.
Writing automated tests involving multiple services is
challenging and It can be difficult to create consistent testing
environments.
Requires high level of automation to manage multiple
instances of different types of services in production.
Everyone has to manage eventual consistency as maintaining
string consistency becomes extremely difficult.
Managing multiple databases and their transactions are
difficult.
Inter-process calls are slow.
Debugging will become difficult.
Complexity in DevOps.
Production monitoring cost is higher.
Formal documentation overhead.
Lack of governance.
1. These block the thread until the task is completed and wait for the
completion of the task. Wait blocks the thread synchronously until the
task completion.
2. Wait and Task.Result both wrap any type of exception in
AggregateException and create complexity while doing exception
handling. If you use the await instead
of Task.Wait and Task.Result then you don’t have to worry about
exception handling.
3. Sometimes, these both block the current thread and
create DEADLOCKS
4. Wait and Task.Result only can be used if parallel task execution is
going on. We recommend that you don’t use it
with Async programming.
PERFORM I/O OPERATIONS ASYNCHRONOUSLY
We can increase the performance of the application if we can reduce the number of
requests to the server every time. The first time, you will make the call to the server
and get the response and this response is stored somewhere for the future for some
time (there will be some expiry) and next time when you will make the call for the
same response then first you will check if you have already got data in the first
request and stored somewhere and if it is yes then you will use the stored data
rather than making the call to the server.
Keeping the data in that location from where we can get it frequently without
making the call to the server is a good practice. Here, we can use the
Cache. Caching the content helps us to reduce server calls again and again and it
helps us to increase the performance of the application. We can do the cache at any
point of a location like on client-side caching, server-side caching or client/server-
side caching.
1. Reduce the number of HTTP calls, which means you should always try
to reduce the number of network round trips.
2. Try to get all the data in one go. This means rather than making
multiple calls to the server, just make one or two calls which can bring
all the required data.
3. Frequently set the cache on data which is not being changed.
4. Don’t try to get the data in advance which is not required, it will
increase the load on the response and your application will load slower.