Prism Avalonia UI framework. Super charge your cross-platform apps with IoC, navigation, and more! Sponsored by Suess Labs. Prism is based on Microsoft patterns and practices.
How do you go about registering services that require an async call? i.e. retrieving values from cloud/APIs.
I was trying to do all these in app.axaml.cs, by overriding OnInitialize() and RegisterTypes().
Doing this at the very start as I saw that we register and setup services and viewmodels here.
Sample #1:
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
var config = await RetrieveConfig();
//RetrieveConfig().GetAwaiter().GetResult();
containerRegistry.RegisterSingleton<IDemoService>(() => new DemoService(config.Prop1, config.Prop2));
}
Sample #2:
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IConfigService, ConfigService>();
containerRegistry.RegisterSingleton<IDemoService, DemoService>();
}
public class DemoService : IDemoService
{
public DemoService(IConfigService configService)
{
var config = configService.RetrieveConfig().GetAwaiter().GetResult();
// set props with retrieved config
}
}
From these two samples, i've reached variations that:
runs synchronously and immediately shows the GUI
and the most frequent scenario, the async call runs, but never returns value to the caller.
Any insights, recommendations will be greatly appreciated!
Hi team,
First time trying avalonia, coming from WPF.
How do you go about registering services that require an async call? i.e. retrieving values from cloud/APIs. I was trying to do all these in app.axaml.cs, by overriding OnInitialize() and RegisterTypes().
Doing this at the very start as I saw that we register and setup services and viewmodels here.
Sample #1:
Sample #2:
From these two samples, i've reached variations that:
Any insights, recommendations will be greatly appreciated!
Thanks!