Before we start, if you don’t feel like reading this article, you can watch it on my YouTube channel:
Asp.Net Core is Microsoft’s platform for creating Web Applications.
All Web applications process Http Requests and return Http Responses. Users send http Requests typically from a browser and the corresponding http responses contain the information that the users requested.
In Asp.Net Core, once the http request is routed to the web server, the http request is then encapsulated in a HttpContext object. After that, the HttpContext object is passed through one middleware after another. Each middleware takes different responsibilities in processing the request. For example, some middleware take care of loading static resources, some take care of generating dynamic contents, some take care of logging and some others may take care of error handling. Middleware should be made according to the single responsibility principle. When processing the requests, middleware may write to the httpcontext object for generating the final http response.
Since all the middleware is linked together, we call the linked middlewware the middleware pipeline. Web Developers are responsible to choose what middleware to use in order solve their particular problems and they are also reponsible for configuring the chosen middleware.
In Asp.Net Core, the web server is actually a console application that runs in an infinite loop while listening to your chosen port for http requests.
When the console application starts, the first thing it needs to do is to configure the middleware pipeline. Asp.Net Core instanciate the Startup class automatically and calls the ConfigureServices method to import the middleware packages and their dependencies and then it automatically calls the Configure method for develoepers to configure the middleware in the middleware pipeline.
It might be helpful for understanding the purpose of the two methods, if you imagine the ConfigureServices method contains the import statement in javascript and the Configure method is where you use those javascript modules. But officially the ConfigureServices method is where developers do dependency injections in order to plug in the services that the middleware will use for processing the http requests.
So you may ask, as Asp.Net Core Web Developers, is it true that my job is to create middleware and configure them. Actually, most of the time, you work within the framework of a certain sets of middleware. Because In Asp.Net Core, above the Asp.Net Core platform, there are three different Application Frameworks: MVC, Razor pages and Blazor. Each framework uses a set of middleware.
When creating MVC web applications or web APIs, you work with models classes, razor views and controlers methods. When creating Razor pages applications, you work with Razor views and their corresponding code behind model classes. When creating Blazor Applications, you work with Blazor Components (aka Razor components).
This summarized what the Asp.Net Core platform is and in future posts, I will talk more about the different application frameworks respectively.