Home > OS >  IConfiguration functionality in C#
IConfiguration functionality in C#

Time:09-24

I'm reading through some code someone wrote and I'm trying to understand it. the code looks like this.

public LocalFileStorageHandler(AftermarketDbContext dbContext, IConfiguration configuration, ILogger<LocalFileStorageHandler> logger)
        {
            _db = dbContext;


            var runDataFolder = configuration["MountPoints:RunData"];
}

for privacy I have only posted a short section of the method. Now my question is what does the last line of code do?

when i console print runDataFolder it gives me a directory address. No idea where this came from what the mountpoints part does, why its square brackets around it.

Any one got some insight?

CodePudding user response:

It means that you have appsettings.json file in a root of the web application. Or it can be appsettings.Environment.json : for example, the appsettings.Production.json or(and) appsettings.Development.json files. You can access a configuration value using the IConfiguration service. In your example this service is injected in the constructor.

There is a json fragment like this inside of this file

"MountPoints": {
    "RunData": "....directory address",
      .....
},
  • Related