Skip to main content
1 of 4
NtFreX
  • 223
  • 2
  • 10

I solved my problem by checking the current active view and only do the navigate when the "unloading view" is active. Because the UnloadUnitOfWork calls the CleanUp method (which is doing the navigation) before the event of the legacy service I can decide there where I need to navigate to.

public class LogoutUnitOfWork
{
    public void Execute()
    {
        new UnloadUnitOfWork().Execute(false);

        // navigate to the "logout view"

        // do some business related work

        // navigate to the "login view" (Logedout state)
    }
}

public class UnloadUnitOfWork
{
    public void Execute(bool navigate = true)
    {
        // navigate to the "unloading view"

        // do some business related work
        _legacyService.Unload();

        CleanUp(navigate)
    }

    public void CleanUp(bool navigate)
    {
        // this method is called twice
        // in case the unloading happened through an
        // event from the legacy service it will only be called once
        if(!IsUnloadingViewActive())
            return;

        // do some buisiness related work

        if(navigate)
        {
            // => navigate to the "logedin view" (LogedIn state)
        }
    }
}

_legacyService.Unloading += (sender, args) =>
{
    // navigate to the "unloading view" if not yet active
};
_legacyService.Unloaded += (sender, args) =>
{
    new UnloadUnitOfWork().CleanUp(true);
};
NtFreX
  • 223
  • 2
  • 10