Repository navigation
Open
Labels
kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification.
Description
Current behavior
I have SomeUtils class that takes
UnoAppNavigation2.zip
in INavigator as ctor parameter, at creation the parameter is null
App.xaml.cs
...omitted for brevity
.ConfigureServices((context, services) =>
{
// TODO: Register your services
//services.AddSingleton<IMyService, MyService>();
services.AddSingleton<ISomeUtils, SomeUtils>();
})
.UseNavigation(RegisterRoutes)
);
MainWindow = builder.Window;
#if DEBUG
MainWindow.EnableHotReload();
#endif
MainWindow.SetWindowIcon();
Host = builder.Build();
await builder.NavigateAsync<Shell>();
}
private void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<MainPage, MainViewModel>(),
new ViewMap<FirstPage, FirstViewModel>(),
new DataViewMap<SecondPage, SecondViewModel, Entity>()
);
routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested:
[
new ("Main", View: views.FindByViewModel<MainViewModel>(),IsDefault:true)
]
)
);
}
}
MainPage.xaml cs getting ISomeUtils class instance
public MainPage()
{
_app = (Application.Current as App);
var somUtils = _app.Host.Services.GetRequiredService<ISomeUtils>();
INavigator navigator = this.Navigator();
this.InitializeComponent();
UrlPath.Text = _app?.MainHref + " base url:"+_app.BaseUrl;
}
SomeUtils class
public class SomeUtils : ISomeUtils
{
private INavigator _navigation;
public SomeUtils(INavigator navigator)
{
_navigation = navigator;
}
public int MyProperty { get; set; }
}
Expected behavior
INavigator should not be null when injected to a SomeUtils class
How to reproduce it (as minimally and precisely as possible)
Build and run project attached, put a brakepoint in SomeUtlis class ctor. INavigator parameter will be null.
Workaround
No response
Works on UWP/WinUI
None
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
No response
Affected platforms
Windows (WinAppSDK)
IDE
Visual Studio 2022
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
No response
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification.

Activity
lhLife commentedon Nov 18, 2024
modify to:
services.AddTransient<ISomeUtils, SomeUtils>();
KWodarczyk commentedon Nov 18, 2024
@lhLife .AddTransient does fix the issue but, it's not ideal as it forces developer to use Transient, even if they want a Singleton, I would treat this as temporary work around. I also think that this should be documented in Uno docs for example somewhere on this page https://platform.uno/docs/articles/external/uno.extensions/doc/Reference/Navigation/Navigator.html
lhLife commentedon Nov 19, 2024
It cannot be a singleton, it can only expose INavigatorFactory or INavigator wrapper。
The entire program is a tree like structure that can be navigated anywhere。
demo:Not real code
Where do you think INavigator should navigate from
lhLife commentedon Nov 19, 2024
The setting of the region is good, but INavigator needs a wrapper class to solve its complexity.
KWodarczyk commentedon Nov 19, 2024
Sorry I don't follow, you have two regions with same name ?
lhLife commentedon Nov 21, 2024
Each page is a separate page.
When you navigate through the Model on Page 4, there are PanelVisilityNavigator and FrameNavigator at the top level, and multiple options will appear. Therefore, they can only be Transient (PanelVisilityNavigator)