C
C#•5mo ago
Raki

Beginner question. what does this createhostbuilder do?

I'm learning .net core and I saw this code in program.cs. I can understand the main method calls this createhostbuilder which in turn sets some config value. But what I don't know is from where this configuration comes. where does this config.AddKeyPerfile do. Can anyone explain
c#
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddKeyPerFile(directoryPath: Path.Combine(Directory.GetCurrentDirectory(), "secrets"), optional: true);
config.AddKeyPerFile(directoryPath: Path.Combine(Directory.GetCurrentDirectory(), "platform-secrets"), optional: true);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
c#
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddKeyPerFile(directoryPath: Path.Combine(Directory.GetCurrentDirectory(), "secrets"), optional: true);
config.AddKeyPerFile(directoryPath: Path.Combine(Directory.GetCurrentDirectory(), "platform-secrets"), optional: true);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
2 Replies
Raki
Raki•5mo ago
I don't see any file with the file name secrets or Platform scerets in the codebase
Sir Rufo
Sir Rufo•5mo ago
Of course not, because they should kept secret and not published to the rest of the world 😉 You should also find that entries in .gitignore file to ensure they were ignored by the repository