Explain the component in Startup File in Core Project

ConfigureServices

This method is used to add services to the container.

The purpose of this is to set up the dependency injection layer. Inside ASP.NET core you must use dependency injection.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
}

Configure

This method is used to configure the HTTP request pipeline. It is used to setup how our request are handled.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();

    app.UseMvc();
}

Startup Constructor

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
    Configuration = builder.Build();
}

results matching ""

    No results matching ""