AutoMapper IValueResolver有异步等效功能吗?

时间:2018-12-14 13:15:31

标签: c# .net asp.net-core .net-core automapper

我有一个解析器

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);
}

0 个答案:

没有答案