Skip to content

How to make constructor injection of INavigator works? #1804

Answered by LITTOMA
LITTOMA asked this question in Q&A
Discussion options

You must be logged in to vote

OK, I figured it out.
I have to call builder.Window.InitializeNavigationAsync so that the navigator can be injected to the constructor correctly.
I also register the navigator instance to the service provider in initialNavigate so I can resolve it anywhere.

builder.Window.InitializeNavigationAsync(
    async () => builder.Build(),
    initialNavigate: async (svc, nav) =>
    {
        svc.AddSingletonInstance<INavigator>(nav);
        await nav.NavigateViewModelAsync<IntroViewModel>(this);
    }
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LITTOMA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant