ValueInjecterを使用して、ドメイン モデルからサービス レイヤー経由で提供される DTO にプロパティをマップしています。問題のサービスは更新も受け入れます...そのため、更新された DTO が渡され、これがドメイン オブジェクトに注入されて保存されます。
// Domain
public class Member
{
public Country Country { get; set; }
}
public class Country
{
public string Code { get; set; }
public string Name { get; set; }
}
//Dto
public class MemberDto
{
public string CountryCode { get; set; }
}
//Transformation Method attempt 1
public Member InjectFromDto (MemberDto dto, Member source)
{
source = source.InjectFrom<UnflatLoopValueInjection>(dto);
return source;
}
上記のコードが行うことはすべて、Property Member.Country.Code を更新することだけですが、これは明らかに私が必要としているものではありません。
したがって、ドキュメントから、オーバーライドを作成する必要があると考え、これを取得しました:
public class CountryLookup: UnflatLoopValueInjection<string, Country>
{
protected override Country SetValue(string sourcePropertyValue)
{
return countryService.LookupCode(sourcePropertyValue);
}
}
//revised transformation call
//Transformation Method attempt 2
public Member InjectFromDto (MemberDto dto, Member source)
{
source = source.InjectFrom<UnflatLoopValueInjection>(dto)
.InjectFrom<CountryLookup>(dto);
return source;
}
私の問題はデバッグ中です。CountryLookup は呼び出されません。
私が考えることができる考えられる理由:
- Nhibernate Proxy クラスにより、値インジェクターが国の型と一致しなくなりますか? 平坦化中に機能するため、これは意味がありません。
- おそらく、何らかの理由で非平坦化が発火していないのでしょう。つまり、Dto は CountryCode であり、ドメインは Country.Code です。
Dto で CountryCode プロパティを使用して countryService.LookupCode を呼び出し、更新プログラムの挿入中に使用する正しいオブジェクトを返す必要があります。