Hi Folks!
I'm currently working on a project with an external Web-API. It supports both Win and Web. You know my knowledge with XAF.Web is not that advanced.
So basically the question is, how to use async await (or any task based api) in a controller for win and web:
C#private async void FetchRemoteObject_Execute(object sender, SimpleActionExecuteEventArgs e)
{
View.CurrentObject = null;
var httpClient = new HttpClient();
var response = await httpClient.GetAsync("/api/foo");
if(response.IsSuccessStatusCode)
{
var payload = JsonConvert.DeserializeObject<MyObject>(await response.Content.ReadAsStringAsync());
View.CurrentObject = payload;
}
}
This will work fine in a win project (cause we have an SynchronizationContext) but not for an web appication. What's the easiest solution to make this in web work? I've found the following docs in MSDN but have to clue where to put that registration logic in a web application. Would be cool if I don't need to duplicate the code for win and web.
Kind regards,
Manuel