Sunday, September 2, 2018

.Net Core | Initialization of Applications

Initialization of .Net core Web Application
  1. No Global.asax
  2. Web application and other application starts from program class contains main method


  3. main method calls another static method CreateWebHostBuilder method that returns object of IWebHostBuilder interface.
  4. CreateWebHostBuilder calls CreateDefaultBuilder static method. 
  5. That creates object of WebHostBuilder setup it and run it.


    • Created object 'builder' of WebHostbuilder
    • UseKestral(): Tells builder to use Kestrel.
      Kestrel
      is embedded internal server that host application and communicate (Request/Response) with external web server like IIS.
    • UseIISIntegration():  Tells to use IIS and communication between IIS and Kestrel.
    • UseContentRoot: Access project directory
    • ConfigureAppConfiguration: Loads appSettings.json file contains settings
    • ConfigureLogging: Configures logging in console window and debug window including in libraries used.
    • UseDefaultServiceProvider: Tells builder to use asp.net core's internal dependency injection container. 
    • ConfigureServices: Used to add types to the internal dependency injection container. Adding type Kestrel that is used.
    • Returns object of WebHostbuilder
  6. Object of WebHostBuilder configured to use Startup class.
  7. Startup Class: Contains 2 methods
    • ConfigureServices: Used to register services in Ioc container
    • Configure: Used to configure Request/Response pipeline
           public class Startup   
           {  
                  public void Configure(IApplicationBuilder app)  
                  {  
                     //Register types (services) to use in application
                  }  
                  public void ConfigureServices(IServiceCollection services)  
                 {  
                     //Configure how to handle http request 
                  }       
           }

No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...