I have the following problem:
I have a class, where I inject Logger via DI.
But at the end I want to instantiate this class.
Here is the code:
public class DokumentInhaltJson : SimpleValueObject<string>
{
public readonly ILogger<DokumentInhaltJson> _logger;
private DokumentInhaltJson(
string value, ILogger<DokumentInhaltJson> logger) : base(value)
{
_logger = logger;
}
public static Result<DokumentInhaltJson> Create(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return Result.Failure<DokumentInhaltJson>("Error message 1");
}
try
{
JObject objectToValidate = JObject.Parse(value);
}
catch (Exception e)
{
return Result.Failure<DokumentInhaltJson>("Error message 2"));
}
return Result.Success(new DokumentInhaltJson(value));
}
}
The problem now is that new DokumentInhaltJson
now wants the logger as a second parameter.
What can I do here?