A, Program Files:
1.CreateWebHostBuilder ():
building web services
2.WebHost.CreateDefaulBuilder ():
Use the default configuration, including
1. Use the Web Server Kestrel
2. integrates IIS
3. configure the Log
4. Creating the implementation IConfiguration interface object, the object can be acquired configuration information file appsettings.json
3.UseStartup <Startup> ()
using a web application to configure class Startup
Two , the Startup file:
1. Call the order is ConfigureServices () after Configure (), called by the runtime.
2.ConfigureServices ():
the service registry to the vessel, may be a third-party component
configuration dependent injection
may be injected into the already arranged directly in the process parameters,
such as: ConfigureServices (IConfiguration config), the interface will be IConfiguration by way of injection achieved by config.GetConnectionString () appsetting.json connection string can get configuration information, config.GetSection ( "ConnectionStrings"). GetSection ( "ProviderName"). Value can press to take a configuration of a node
3. configure ():
configure the http request pipeline, for example: session, cookie
a middleware component added to the request pipeline, for example: app.UseMvc () method to add extensions to the intermediate route request pipeline, and configured as the default handler MVC .
You can also customize the middleware
Three , .NET dependency injection Core built
in file ConfigureServices Startup () method
1.services.AddSingleton (), create a singleton object
2.services.AddTransient (), each time an object is created
3.services.AddScoped () , a http request to create an object
Fourth, the intermediate
1. Under Configure Startup file () method
app.Use ... (intermediate configuration parameters), such as:
public void the Configure (App IApplicationBuilder, IHostingEnvironment the env) { // Add to HTTPS redirects HTTP requests to the middleware. app.UseHttpsRedirection (); // enable static files for the current request path app.UseStaticFiles (); app.UseMvc (routes => { routes.MapRoute ( name: " default " , Template: " {= Home Controller} / { Longin} = Action / {ID}? " ); }); }
2. Custom middleware, please refer to my another blog post https://www.cnblogs.com/yijiayi/p/10964418.html