我有以下问题:
我有一堂课,我通过 DI 注入 Logger。
但最后我想实例化这个类。
这是代码:
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));
}
}
现在的问题是,new DokumentInhaltJson
现在希望将记录器作为第二个参数。
我可以在这里做什么?