Q16. Difference between concurrency and parallelism?
Q17. What is httpclientFactory?
Q18. Example of Nuget Middlewares, System inbuild middlewares?
Q19. Example of custom middlewares.
Q20. Steps to implement Repository pattern with EntityFrameworkCore in dotnet 8?
=======================================================================
Q16. Difference between concurrency and parallelism?
Answer:
Concurrency - It means executing multiple tasks on same core. In this case the same core switches between multiple tasks and giving a feel that multiple tasks are excuting in parallel but in actual core is executing all of them little by little. Concurrency is a feel of parallelism.
1. It is used to bring non blocking architecture. Means non of your task is blocked and the end user will keep seeing output of other tasks. The goal of this is not performance but making the feel of application as non blocking. This ensure to make application user friendly.
2. its a async-await feature. In which the caller(the parent method, usually method of main class) doesn't wait for completion of child method and move ahead. on getting data at await level, method thread will come back.
3. Single thread picking multiple items to keep non blocking code. No good in performance but caller will not hanged up and remain unblocked.
Parallelism - Executing multiple tasks on multiple cores.
1. It is used to bring parallelism
2. Task is the feature. Threads are used as concept. Now it will create different threads for differnt task.
3. It uses all cores present in system and give good performance. Multi threading is another word for it.
For code level example and better understanding visit below
=======================================================================
Q17. What is httpclientFactory?
Answer:
A new HttpClientFactory feature comes with ASP.NET Core 2.1 which helps to solve some common problems that developers may run into when using HttpClient instances to make external web requests from their applications.
The main issue is when you create too many HttpClients within your code which can in turn into a problem ie socket Exhaustion. Where you have basically used up too many sockets too fast. There is a limit on how many sockets you can have open at one time. When you dispose of the HttpClient, the connection it had open remains open for up to 240 seconds in a TIME_WAIT state (in case any packets from the remote server still come through).
WATCH the youtube link for quick review. (IMP video)
=======================================================================
Q18. Example of Nuget Middlewares, System inbuild middlewares?
Answer:
Nuget:
EntityFrameworkCore
CORS
Framework:
UseStaticFiles
UseRouting
UseAuthorization
UseAuthentication
=======================================================================
Q19. Example of custom middlewares.
Answer:
We have custom middleware for acknowledgement. We have 3rd party service which is giving inbound json data to our api. We have a middleware which send acknowledge of reading that json file and processing all the data correctly or not. so that 3rd party service is aware of proper data flow.
=======================================================================
Q20. Steps to implement Repository pattern with EntityFrameworkCore in dotnet 8?
Answer:
1. Create dotnet core project and install nuget packages
dotnet new webapi -n MyNewApp
cd MyNewApp
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
2. Define entity class and create a DBContext class. Give reference of entity class as DbSet property in DBContexct class.
3. Define IMyRespository and implement MyRepositoryClass
4. Register the Repository in DIContrainer in program.cs class
5. Inject the Repository in Controller Constructor and use it for calling methods.
=======================================================================

