我有一个解析器
public class MyValueResolver : IValueResolver<Entity, Dto, List<InnerDto>>
{
private readonly IService _service;
public MyValueResolver(IService service)
{
_service = service;
}
public List<InnerDto> Resolve(
Entity source,
Dto destination,
List<InnerDto> destMember,
ResolutionContext context)
{
IEnumerable<InnerDto> innerDtos =
_service.GetAsync(/*...*/).Result; // .Result block thread.
return innerDtos.ToList();
}
}
.Result
执行同步操作并阻塞线程。
对于这种情况是否有任何解决方法,例如,最好有一些IAsyncValueResolver
public interface IAsyncValueResolver<in TSource, in TDestination, TDestMember>
{
Task<TDestMember> ResolveAsync(TSource source, TDestination destination, TDestMember destMember, ResolutionContext context);
}