• ConfigureServices(IServiceCollection services):
    This method is responsible for registering the services that your application will use. Think of it as telling ASP.NET Core what dependencies your application has and how to create instances of those dependencies. This is the heart of the Dependency Injection (DI) container setup.
    • IServiceCollection services: This parameter is a collection interface provided by ASP.NET Core. You use its methods to add services to the DI container.
    • Common Action : 
      Adding framework services like MVC, Razor Pages, Blazor, gRPC.
      Registering your own custom services (business logic, data access, etc.)
      Configuring options for various features. 
      Adding authentication and authorization services. 
      Registering database contexts (e.g., for Entity Framework Core). 
      Adding caching services (e.g., MemoryCache, DistributedCache).

 

  • Configure(IApplicationBuilder app, IWebHostEnvironment env):
    • This method is responsible for configuring the HTTP request pipeline. It defines how your application will process incoming HTTP requests. You add middleware components to this pipeline, and the order in which you add them is crucial.
    • IApplicationBuilder app: This parameter provides methods for adding middleware components to the request pipeline
    • Common Actions:
      Adding middleware for handling exceptions
      Enforcing HTTPS redirection. 
      Serving static files (CSS, JavaScript, images). 
      Enabling routing. 
      Adding authentication and authorization middleware. 
      Mapping endpoints for controllers, Razor Pages, Blazor, gRPC.
      Adding custom middleware components.

 

In Modern ASP.NET Core (with Program.cs as the entry point):
While the explicit Startup.cs file is often omitted in newer versions,

 


Related Question