SelAromDotNet
SelAromDotNet

Reputation: 4815

Cannot use async/await in Sitefinity MVC Controller Actions

I'm cross posting this question from the Sitefinity forum to gather as many strategies as possible. This question is similar to this one, but I'm posting it anyway to get feedback on which of the suggested workarounds we've come up with might be a better fit.

Sitefinity supports the creation of widgets using MVC Controllers. However, these controllers cannot be async nor return Task<>. Usually, this is fine as we would normally be interacting with Sitefinity data, which has managers that are not asynchronous.

However, in this case, we are creating widgets that will be showing data coming from a 3rd party API, and are using HttpClient to fetch that data, and those operations are async. To be clear, these are server-to-server api calls, and can't be done directly via client-side ajax calls.

From what I've been able to research and read about this, the prevailing strategy is to replace HttpClient with WebClient and make the calls synchronous (as suggested here). This seems simple enough but I'm concerned that this may impact performance since we expect peak times to handle several hundred if not thousands of users at once, and these are purchasing transactions, so it is especially important that they are performant...

the only other strategy I can think of is to implement this part of the site as a SPA using angular and doing everything on the client side. But we don't want to expose our API calls on the client side, so we'd have to build a proxy to pass them through on the server side, probably using a regular controller ("classic" as it is called in Sitefinity, one that does not drive widgets).

Are there any other strategies we can leverage to make async calls in a controller that does not support async? Would you agree that making the calls synchronous via WebClient is the better choice in this case? If not, what other option would you suggest to work around this limitation?

Upvotes: 1

Views: 725

Answers (1)

Victor Leontyev
Victor Leontyev

Reputation: 8736

Usually, async methods are working like that: enter image description here

All async actions invoked by AsyncControllerActionInvoker class.

But this will not work for sitefinity, because Telerik.Sitefinity.Mvc.ControllerActionInvoker (who is processing mvc widgets) is synchronous.

I am pretty sure that other limitations might be not only in "Invoke Action" level, somewhere deeper. I think only Sitefinity core developers can answer to this question in deep details

Upvotes: 4

Related Questions