Everything starts from Program.cs
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
CreateDefaultBuilder extension method will create a default configuration which will look first into appsettings.json
files then will look for Environment variables and at the end, it will use command line arguments.
This part will also set up default logger sources (debug and console) and load the settings for logging from appsettings.json.
After the CreateDefaultBuilder
finishes, then Startup
class is executed. First, the constructor code is executed. After that, services are added to DI container via AddServices
method that lives in Startup class. After that, an order of middleware that will handle every incoming request is set up.