Automapperを使用して、すべてのDateTimeをUTCからローカルタイムに変換しようとしていますが、ITypeConverterにインターフェイスを注入する必要があります。アプリケーションを実行するときにこのエラーが発生します。MissingMethodException:このオブジェクトに対して定義されたパラメータのないコンストラクタはありません。ITypeConverterを使用したAutoMapper Dependency Injection
私はこの問題が依存性注入コードにあると思います!
誰でも手伝ってもらえますか?
UserRepository:
public class UtcToLocalConverter : ITypeConverter<DateTime?, DateTime?>
{
public UtcToLocalConverter(IBaseSettings baseClass) // I tried to inject here!!!
{
Settings = baseClass;
}
private IBaseSettings Settings { get; }
public DateTime? Convert(DateTime? source, DateTime? destination, ResolutionContext context)
{
if (source == null) return null;
var tzi = TimeZoneInfo.FindSystemTimeZoneById(Settings.UserData.TimeZone);
return TimeZoneInfo.ConvertTime(DateTime.SpecifyKind((DateTime)source, DateTimeKind.Utc), tzi);
}
}
コードをスクリーンショット画像として投稿しないでください。関連するコードをコピーして質問に貼り付けることはできますか? –
@NateBarbettini提案をありがとう!あなたはこのことについてどう思いますか? – JhobanyPena