I have a class in which data that needs to be shown to the user is kept. I want to use Localizer for this class and ı wrote custom DisplayName Attribute class for this. But ı cant access IStringLocalizer from this class. How can i acces this class can u help me pls. This is my Custom class.
public class CustomName:DisplayNameAttribute
{
static IStringLocalizer<CustomName> _localizer;
private readonly ServiceProvider _di;
public CustomName(IStringLocalizer<CustomName> localizer)
{
_localizer = localizer;
}
public CustomName(string key) : base(Lookup(key)) { }
static string Lookup(string key)
{
if (_localizer == null) {
//always getting here cause constructor wont run
}
try
{
return _localizer.GetString(key);
}
catch
{
return key; // fallback
}
}
}
How can i access localizer object without depencency injection ?