Search This Blog

Wednesday, June 16, 2021

Q31-Q35

Q31. Difference between Middleware and filters in .net core mvc?
Q32. Life cycle of dotnet 8 MVC application?
Q33. When to use middleware and when to use filters in .net core?
Q34: What is CLEAN or Onion architecture design pattern?

=======================================================================Q31. Difference between Middleware and filters in .net core mvc?

Answer:
Middlewares
1) They are part of .net core and have access to httpcontext objects. they can be present even is project is not in mvc, api structure. 
2) Good in case you want to do changtes at httpcontet objects like authentication etc. 

Filters
1) They are present only in case of MVC and api. 
2) Good in case you want tocheck something around MVC contexts objects like post action filter

=======================================================================Q32. Life cycle of .net core MVC application?

Answer:
Life cycle of .net core application consists of two parts = 1st life cycle part specific to .net core + 2nd General life cycle part of MVC. 
  1. program.cs
  2. Authentication, Authorization etc middlewares
  3. Routing middleware will create routing map on hosted application server
  4. Controller 
  5. Action
  6. View
=======================================================================Q33. When to use middleware and when to use filters in .net core?

Answer:
Filters are something specific to MVC patterns that can be applied on top of our controllers. 
Filters and Middleware does the same functionality, but main difference lies in their scope. 

Middleware applies globally to all requests. eg : logging request and response, Handling exceptions globally, Managing CORS, Authentication/ Authorization. 

Filters applies specifically to a controller to an action of a controller. its mainly used to do validation of the model. 

=======================================================================






=======================================================================
Q34: What is CLEAN or Onion architecture design pattern?

Answer:
The Clean Architecture, often also referred to as Onion Architecture, is a software design pattern that aims to separate concerns and enforce dependency inversion, making systems more maintainable, testable, and adaptable to changes.
     
Key Concepts:
Clean Architecture is composed of layers arranged like an onion, where:
Core logic is at the center and Outer layers depend on inner layers, but not the other way around.



=======================================================================

Monday, June 14, 2021

Q26-Q30

Q26. What is the use of appsettings.json in .net core?
Q27. What are user secrets in .net core?
Q28. What is reverse proxy server .net core?
Q29. What is the use of launchSettings.json file in .net core?
Q30. What is the difference between  MapWhen and Map in dotnet 8?

==========================================================================================
Q26. What is the use of appsettings.json in .net core?

Answer:
1) Used to store configuration settings such as connection string, application level global variable, logging level configurations etc
2) We can store JWT key in appsettings.json file but it is NOT advisable. it can be saved here for temporary development phase. 
3) appSettings.json file could be environment specific as well. appsettings.<environment>.json

==========================================================================================
Q27. What are user secrets in .net core?

Answer:
If we do not want to share the secrets like API keys, connection string, connection information to cloud service (azure, aws) etc to anyone who can clone your project. 

For this .net core has given an option of user secret file which is outside the project tree structure. you can manage this file by right click the project and choose manage secrets option. 

Secret.json is the file which will be created to store secrets. 




==========================================================================================
Q28. What is reverse proxy server .net core?

Answer:
1) reverse proxy came into picture when we are using kestral server in .net core. 
2) Kestrel can be used by itself or with a reverse proxy server, such as Internet Information Services (IIS), Nginx, or Apache. A reverse proxy server receives HTTP requests from the network and forwards them to Kestrel.



==========================================================================================
Q29. What are the use of launchSettings.json file in .net core?

Answer:
launchSetting.json under property folder is mainly for local development. 
Hosted application url in local, Environment variables are part of launchSettings.json file. 


==========================================================================================
Q30. What is the difference between Map and MapWhen in dotnet 8?

Answer:
Both Map and MapWhen are used to branch middleware pipeline. 

Map: 
This method is used to branch the pipeline based on specific requested path. 

app.Map("/maptest", HandleMapTest);

MapWhen:
Enables branching pipeline. Runs specified middleware if condition is met.


    app.MapWhen(context => {
        return context.Request.Query.ContainsKey("somekey");
    }, HandleBranch);
==========================================================================================

Q36-Q40(EF)

Q36.  What is the difference between Include and Join in entity framework? Q37. What will be your approach in case you want to call a manual...