See below code snippet. I implemented override OnInitialized() as suggested in your samples project. However, my Close() method was being called during navigation to/from this page, regardless if the dialog was ever shown or not.
As you can see below, I commented this out, and implemented the DialogService.OnClolse +/- all within one method that actually opens the dialog - and this seems to work fine ... so I seem to have worked around this OR is this the preferred way anyhow?
In any case, please note this as perhaps you have a bug: the OnClose event handler should not be getting called if the dialog was never opened.
From "LoginComponent.razor":
[Inject]
DialogService DialogService { get; set; }
//protected override void OnInitialized()
//{
// DialogService.OnClose -= Close;
// DialogService.OnClose += Close;
//}
AppUser AppUser { get; set; }
async Task ShowRegistrationDialog()
{
DialogService.OnClose -= Close;
DialogService.OnClose += Close;
AppUser = new AppUser("Registration");
await DialogService.OpenAsync(Resources.Register, ds => @<RegistrationComponent AppUser="@AppUser"/>);
DialogService.OnClose -= Close;
}
[Inject]
IStorage Storage { get; set; }
void Close(dynamic result)
{
Storage.AddRange(new Data[] { AppUser });
}