Migrating App.xaml.cs OnX() to Prism MAUI? #3036
-
Hi there, I have been using the App.xaml.cs protected override void OnStart() I notice that in MAUI/Prism we still have the App.xaml.cs. But we also have the PrismBuilder OnAppStart() How do they compare? When to use the App.xaml.cs OnStart() and when to use the OnAppStart()? We will be a paying customer starting in January. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To be honest As for the Application public partial class App
{
private IEventAggregator _ea { get; }
public App(IEventAggregator ea)
{
_ea = ea;
InitializeComponent();
}
protected override void OnStart()
{
// invoke an event with the IEventAggregator
}
protected override void OnResume()
{
var services = Handler.MauiContext.Services;
if (services is null)
return;
var nav = services.GetService<INavigationService>();
nav.NavigateAsync("/LoginPage");
}
} |
Beta Was this translation helpful? Give feedback.
To be honest
OnAppStart
should probably be renamedCreateDefaultWindow
. Something to consider when migrating from Xamarin.Forms to .NET MAUI is that while Application.MainPage does still technically exist it is really there for backwards compatibility. Ultimately they should have removed it from the MAUI API.As for the Application
OnStart
,OnSleep
, andOnResume
there are a couple of options you would have. Generally speaking I would suggest using standard Dependency Injection for any services you may need to access in those methods or any others in the Application. However if you needed to resolve the INavigationService I would generally suggest lazy loading it through theHandler.MauiCo…