[ASP.NET Core] and AddMvcCore the difference AddMvc

AddMvcCore() method only adds the core MVC services.

AddMvc() method adds all the required MVC services.

AddMvc() method calls AddMvcCore() method internally.

  

  AddMvcCore () more simple, just add the MVC core services.

  The AddMvc () to add all the components needed for MVC.

  AddMvc () internally calls the AddMvcCore (), which also makes AddMvcCore (more important).

  ASP.Net is an open source project,> GitHub address

  Posted AddMvc source will be more clear.

  

public  static IMvcBuilder AddMvc ( the this IServiceCollection Services) 
        { 
            IF (Services == null ) 
            { 
                the throw  new new ArgumentNullException The (NameOf (Services)); 
            } 

            var Builder services.AddMvcCore = (); // start here, are based AddMvcCore () as the basis for a variety of services to add. 

            builder.AddApiExplorer (); 
            builder.AddAuthorization (); 

            AddDefaultFrameworkParts (builder.PartManager); 

            // the Order added Affects. Options Setup the Order 

            // the Default Framework the Order 
            builder.AddFormatterMappings (); 
            builder.AddViews ();
            builder.AddRazorViewEngine();
            builder.AddRazorPages();
            builder.AddCacheTagHelper();

            // +1 order
            builder.AddDataAnnotations(); // +1 order

            // +10 order
            builder.AddJsonFormatters();

            builder.AddCors();

            return new MvcBuilder(builder.Services, builder.PartManager);
        }

 

  AddMvcCore Source:

  

 1 public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services)
 2         {
 3             if (services == null)
 4             {
 5                 throw new ArgumentNullException(nameof(services));
 6             }
 7 
 8             var partManager = GetApplicationPartManager(services);
 9             services.TryAddSingleton(partManager);
10 
11             ConfigureDefaultFeatureProviders(partManager);
12             ConfigureDefaultServices(services);
13             AddMvcCoreServices(services);
14 
15             var builder = new MvcCoreBuilder(services, partManager);
16 
17             return builder;
18         }

 

Transfer tubing> ASP NET Core AddMvc VS AddMvcCore

Guess you like

Origin www.cnblogs.com/braink-1400/p/11316977.html