Hi @polaro ,
As far as I think,instead of creating variables, you're better off injecting a service that will generate the values you need as required.For example:
public interface ILocalisationService
{
string CurrencySymbol { get; }
}
public class LocalisationService : ILocalisationService
{
private IConfigurationService _configurationService;
private string _currencySymbol;
public LocalisationService(IConfigurationService configurationService)
{
_configurationService = configurationService;
}
public string CurrencySymbol => string.IsNullOrEmpty(_currencySymbol)
? _currencySymbol = _configurationService.GetValue("£")
: _currencySymbol;
}
Now inject the new service:
@inject ILocalisationService LocalisationService
And use it in your view:
The currency symbol is @LocalisationService.CurrencySymbol
Best regards,
Yijing Sun
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.