asp.net core 3.1 learning notes - start execution sequence

1, Preparation environment:

1. Development tools: Microsoft Visual Studio Professional 2019 version 16.4.4;

2.SDK: dotnet-sdk-3.1.101-win-x64;

2, To create a project, select WebAPI:

The project structure is as follows:

Then add the console output statement with corresponding name to each object method in it, and the transformation is as follows:

The contents of Program.cs are as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace NetCoreApi
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        #region transform two groups of execution methods, and compare the start-up execution sequence
        //1. group 1
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(builder =>
                {
                    Console.WriteLine("ConfigureAppConfiguration");
                })
                .ConfigureServices(builder =>
                {
                    Console.WriteLine("ConfigureServices");
                })
                .ConfigureLogging(builder =>
                {
                    Console.WriteLine("ConfigureLogging");
                })
                .ConfigureHostConfiguration(builder =>
                {
                    Console.WriteLine("ConfigureHostConfiguration");
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    Console.WriteLine("ConfigureWebHostDefaults");
                    webBuilder.UseStartup<Startup>();
                });

        /*
         //2.Second group
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                Console.WriteLine("ConfigureWebHostDefaults");
                webBuilder.UseStartup<Startup>();
            })
            .ConfigureServices(builder => {
                Console.WriteLine("ConfigureServices");
            })
            .ConfigureLogging(builder => {
                Console.WriteLine("ConfigureLogging");
            })
            .ConfigureAppConfiguration(builder => {
                Console.WriteLine("ConfigureAppConfiguration");
            })
            .ConfigureHostConfiguration(builder => {
                Console.WriteLine("ConfigureHostConfiguration");
            });
            */ 
        #endregion
    }
}

The contents of the Startup.cs file are as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace NetCoreApi
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            Console.WriteLine("Startup");
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            Console.WriteLine("Startup.ConfigureServices");
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            Console.WriteLine("Startup.Configure");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

After the transformation of the above documents, the results of comparison between the two groups (the first group and the second group) are as follows:

 

The process of starting execution sequence is as follows:

Finally, we attach the learning course of geek time and the rise of. net core. We welcome more small partners to join in learning and build a more prosperous ecosystem;

43 original articles published, 38 praised, 50000 visitors+
Private letter follow

Tags: SDK

Posted on Wed, 05 Feb 2020 09:31:50 -0500 by primuz