question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support async operation in ValueResolver natively

See original GitHub issue

Currently I have the following code:

public class OrderNumberResolver : ValueResolver<Order, int>
{
    private readonly IOrderService _service;

    public OrderNumberResolver(IOrderService service)
    {
        _service = service;
    }

    protected override int ResolveCore(Order order)
    {
        return Task.Run(async () => await _service.GetOrder(order.OrderId))
                    .Result
                    .OrderNumber;
    }
}

But it would be nice to have something like that:

public class OrderNumberResolver : ValueResolver<Order, int>
{
    private readonly IOrderService _service;

    public OrderNumberResolver(IOrderService service)
    {
        _service = service;
    }

    protected override async Task<int> ResolveCoreAsync(Order order)
    {
        var order = await _service.GetOrder(order.OrderId);
        return order.OrderNumber;
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
adamhathcockcommented, Feb 14, 2017

This is what I came up with: https://github.com/Narochno/Narochno.AsyncMapper

People seem to disagree that I should need to do this at all. Composing a domain object from multiple sources feels like a valid use case and some of those sources would need to be async.

1reaction
jbogardcommented, May 14, 2016

Well that makes two of us!

On Sat, May 14, 2016 at 11:36 AM, Alexander Batishchev < notifications@github.com> wrote:

I’m not really familiar with the internal (context, etc.) so wondering is the right way to do async.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/AutoMapper/AutoMapper/issues/1226#issuecomment-219229927

Read more comments on GitHub >

github_iconTop Results From Across the Web

AutoMapper Custom Value Resolvers async
I want to convert BotViewModel to Bot using AutoMapper. There is an example input below from type BotViewModel .
Read more >
Support async operation in ValueResolver natively
Currently I have the following code: public class OrderNumberResolver : ValueResolver<Order, int> { private readonly IOrderService _service; ...
Read more >
Async functions | Can I use... Support tables for HTML5 ...
Async functions make it possible to treat functions returning Promise objects as if they were synchronous. Usage % of. all users, all tracked,...
Read more >
Asynchronous support
Any view can be declared async by making the callable part of it return a coroutine - commonly, this is done using async...
Read more >
Does PHP really not support asynchronous calls natively?
Caller can put in Guzzle\Promise\Coroutine function myAsyncFn(): Generator ... So you can say it: PHP supports async programming natively.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found