Create a class to represent your settings and then methods that would do what you want, e.g. the below. Can do it in a .NET Core console app too doesn't have to be ASP.NET Core.
public class YourSettings
{
public string Root { get; set; }
public string Log { get; set; }
public string Data { get; set; }
public string LogPath => Log.Replace("{Root}", Root);
public string DataPath => Data.Replace("{Root}", Root);
}
Then register it:
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
...
// Configure Options using Microsoft.Extensions.Options.ConfigurationExtensions
services.Configure<YourSettings>(Configuration.GetSection(nameof(YourSettings))); // for your specific example just pass in the string "Directories" since you don't have a section called "YourSettings" - obviously just update the class to encompass whatever settings you want it to
services.AddSingleton(Configuration); //for DI
...
}
Then use it:
private readonly YourSettings _settings;
public YourController(IOptions<YourSettings> settings)
{
_spDataRepo = spDataRepo;
_settings = settings.Value;
DoStuffWithSettings();
}
public void DoStuffWithSettings()
{
Debug.Print($"Hey the logs are here: {_settings.LogPath}");
}