'Initialise persistant value on instantiable class based on appconfig
How do I create a persistant value on a class that stays the same each time it is created?
public record StorageUrl
{
public string FileName { get; set;}
public string BaseAddress {get; set;}
public string FullPath => $"{BaseAddress}/{FileName}";
}
I would like the value of BaseAddress to come from a config file.
My current apporach is to inject IOptions<BaseAddressSettings> each time I want to initialise a StorageUrl is there a way to set the BaseAddress without having to inject IOptions each time.
I would like to initalise the class like
var storageUrl = new StorageUrl { FileName = "fileName" };
I am currently initalising like so
var storageUrl = new StorageUrl
{
FileName = "fileName",
BaseAddress = options.BaseAddress
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
