Answer the question
In order to leave comments, you need to log in
What is the significance of the arguments to the Main() method in creating an IHost object?
We have a Program class of an empty web application:
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 ASP_NET_Core_Lessons
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Answer the question
In order to leave comments, you need to log in
From the C# Programming Guide on MSDN :
The parameter of the Main method is a String array that represents the command line arguments
class Program
{
static void Main(string[] args)
{
foreach (var arg in args)
{
Console.WriteLine(arg);
}
}
}
MyApp.exe Arg1 Arg2 Arg3
MyApp.exe "Arg 1" "Arg 2" "Arg 3"
Copy.exe C:\file1.txt C:\file2.txt
The following defaults apply to the returned HostBuilder:
Set the ContentRootPath to the result of GetCurrentDirectory()
Load host IConfiguration from prefixed environment variables "DOTNET_"
Load host IConfiguration from supplied command line arguments
Load application IConfiguration from "appSettings.json" and "appSettings.[EnvironmentName]. JSON
load application IConfiguration from user secrets when EnvironmentName is "Development" using input assembly
Load application IConfiguration from environment variables
Load application IConfiguration from supplied command line arguments
Configuring an ILoggerFactory for logging to console, debug, and event source output
includes scope checking in the dependency injection container if EnvironmentName is "Development"
Represents a set of application configuration properties as key/value pairs.
Set the ContentRootPath to the result of GetCurrentDirectory()
Load the IConfiguration node from the prefixed environment variables "DOTNET_"
Load the application's IConfiguration from "appSettings.json" and "appSettings.[EnvironmentName]
.json load the app's IConfiguration from user secrets when EnvironmentName is "Development" with input assembly
Loading applications' IConfiguration from environment variables
Setting the ILoggerFactory to log to console, debug, and event source output
includes scope checking in the DI container if EnvironmentName is "Development"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question