C# Input Delegate Requirements

Viewed 38

I am trying to better understand how one understands the requirements of a delegate function parameter to a function. In other words, how does one know which operations need to be performed in the delegate?

For example, HostBuilder.ConfigureAppConfiguration method takes as input a configureDelegate.

How do we know what to do within the expression provided as input such as below:

var builder = WebApplication.CreateBuilder(args);

builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
{
    config.AddJsonFile("MySubsection.json",
                       optional: true,
                       reloadOnChange: true);
});

builder.Services.AddRazorPages();

var app = builder.Build();
1 Answers

Hope this will help you to understand the concept, for more detail visit Action delegate

public void ConfigureAppConfiguration(Action<HostingContext,Config> configuration) {

 var configData = configuration();

 //Further process 

}


// how it invoke  
ConfigureAppConfiguration((context,config)=> {

config.AddJsonFile("MySubsection.json",
                       optional: true,
                       reloadOnChange: true);

});
Related