Total Page Preview: 000000001666
What is the role of ConfigureServices and Configure method in Asp.Net Core MVC in English and Hindi
Configure services and Configure method in Engilsh
In ASP.NET Core MVC, the ConfigureServices and Configure methods are fundamental parts of the application startup process. They play a crucial role in configuring and setting up various services and middleware for your web application.
ConfigureServices Method:
-
The ConfigureServices method is typically found in the Startup class of your ASP.NET Core MVC application.
-
Its primary purpose is to configure and register services that your application depends on using the built-in Dependency Injection (DI) container.
-
You can add services such as database contexts, authentication providers, authorization policies, custom services, and more in this method.
-
This method is called during the application's startup, and it is responsible for setting up the service collection that will be used throughout the application's lifetime.
For example, you might configure your database context like this:
Configure Method:
-
The Configure method is also located in the Startup class and is responsible for configuring the HTTP request pipeline.
-
It receives an IApplicationBuilder instance, which allows you to specify the order and configuration of middleware components that will process incoming HTTP requests.
-
You can add middleware components for routing, authentication, authorization, exception handling, logging, and any other behavior you want to apply to incoming requests.
-
This method is called once during application startup and defines the order in which middleware components are executed.
Here's an example of configuring middleware for routing and MVC:
In summary, the ConfigureServices method is responsible for configuring and registering services, while the Configure method is responsible for configuring the middleware pipeline that processes incoming HTTP requests. Together, these methods are key components of ASP.NET Core's request processing pipeline and application configuration.
Configure services and Configure method in Hindi
ASP.NET Core MVC mein ConfigureServices aur Configure methods ka mahatvapurna bhaag hai, jo aapke web application ke set up aur configuration mein mukhya bhumika nibhate hain.
ConfigureServices Method:
-
ConfigureServices method aksar aapke ASP.NET Core MVC application ke Startup class mein hota hai.
-
Iska pramukh uddeshya aapke application ke liye avashyak services ko configure aur register karna hota hai, jise built-in Dependency Injection (DI) container ka upayog karke kiya jata hai.
-
Aap is method mein database contexts, authentication providers, authorization policies, custom services, aur anya services jaise cheezen add kar sakte hain.
-
Is method ko application ki shuruaat ke dauraan call kiya jata hai, aur yah service collection ko set up karta hai, jo application ke jivan kaal ke dauran istemal kiya jayega.
Uddeshya ki drishti se, aap apne database context ko is tarah configure kar sakte hain:
Configure Method:
-
Configure method bhi Startup class mein hota hai aur HTTP request pipeline ko configure karne ke liye jimmedar hota hai.
-
Ismein ek IApplicationBuilder instance milta hai, jise istemal karke aap incoming HTTP requests ko process karne ke liye middleware components ki vyavastha aur configuration kar sakte hain.
-
Aap routing, authentication, authorization, exception handling, logging, aur anya vyavhaar ko apply karne ke liye middleware components ko add kar sakte hain.
-
Yah method application shuruaat ke dauraan ek baar call hota hai aur middleware components ke kriyanvayan ke kram ko define karta hai.
Neeche ek example diya gaya hai routing aur MVC ke liye middleware ko configure karne ka:
Samanya roop se kaha jaye to, ConfigureServices method service ko configure aur register karne ke liye jimmedar hota hai, jabki Configure method incoming HTTP requests ko process karne wale middleware pipeline ko configure karne ke liye jimmedar hota hai. In dono methods ka saath mil kar ASP.NET Core ke request processing pipeline aur application configuration ka mahatvapurna hissa hai.
Thank You
About Author
Brijesh Kumar
Database Developer
I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL
Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall
and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com