diff --git a/src/Controls/src/Core/Routing.cs b/src/Controls/src/Core/Routing.cs index 623f06b67bc0..46803c3e0ca5 100644 --- a/src/Controls/src/Core/Routing.cs +++ b/src/Controls/src/Core/Routing.cs @@ -158,23 +158,6 @@ public static Element GetOrCreateContent(string route, IServiceProvider services if (s_routes.TryGetValue(route, out var content)) result = content.GetOrCreate(services); - if (result == null) - { - // okay maybe its a type, we'll try that just to be nice to the user - var type = Type.GetType(route); - if (type != null) - { - if (services != null) - { - result = (services.GetService(type) ?? Activator.CreateInstance(type)) as Element; - } - else - { - result = Activator.CreateInstance(type) as Element; - } - } - } - if (result != null) SetRoute(result, route); @@ -284,9 +267,10 @@ public override Element GetOrCreate(IServiceProvider services) { if (services != null) { - return (services.GetService(_type) ?? Activator.CreateInstance(_type)) as Element; + return (Element)(services.GetService(_type) ?? Activator.CreateInstance(_type)); } - return Activator.CreateInstance(_type) as Element; + + return (Element)Activator.CreateInstance(_type); } public override bool Equals(object obj) diff --git a/src/Controls/tests/Core.UnitTests/ShellNavigatingTests.cs b/src/Controls/tests/Core.UnitTests/ShellNavigatingTests.cs index bdfc4f4a39b0..83830e5f679a 100644 --- a/src/Controls/tests/Core.UnitTests/ShellNavigatingTests.cs +++ b/src/Controls/tests/Core.UnitTests/ShellNavigatingTests.cs @@ -623,11 +623,11 @@ public async Task RouteWithGlobalPageRoute() Assert.AreEqual("//animals/domestic/cats/catdetails", shell.CurrentState.Location.ToString()); } - [TestCase(typeof(PageWithDependency), typeof(PageWithDependency))] - [TestCase(typeof(PageWithDependencyAndMultipleConstructors), typeof(PageWithDependencyAndMultipleConstructors))] - [TestCase(typeof(PageWithDependency), typeof(Dependency))] - [TestCase(typeof(PageWithUnregisteredDependencyAndParameterlessConstructor), typeof(PageWithUnregisteredDependencyAndParameterlessConstructor))] - public async Task GlobalRouteWithDependencyResolution(Type typeForRouteName, Type type) + [TestCase(typeof(PageWithDependency))] + [TestCase(typeof(PageWithDependencyAndMultipleConstructors))] + [TestCase(typeof(PageWithDependency))] + [TestCase(typeof(PageWithUnregisteredDependencyAndParameterlessConstructor))] + public async Task GlobalRouteWithDependencyResolution(Type pageType) { var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient(); @@ -646,21 +646,21 @@ public async Task GlobalRouteWithDependencyResolution(Type typeForRouteName, Typ Items = { flyoutItem } }; shell.Parent.Handler = fakeHandler; - var routeName = typeForRouteName.AssemblyQualifiedName; - Routing.RegisterRoute(routeName, type); + var routeName = pageType.Name; + Routing.RegisterRoute(routeName, pageType); await shell.GoToAsync(routeName); Assert.IsNotNull(shell.Navigation); Assert.IsNotNull(shell.Navigation.NavigationStack); var page = shell.Navigation.NavigationStack[1]; Assert.That(page, Is.Not.Null); - if (type == typeof(PageWithDependency) || type == typeof(Dependency)) + if (pageType == typeof(PageWithDependency) || pageType == typeof(Dependency)) { Assert.IsInstanceOf(page); Assert.That((page as PageWithDependency).TestDependency, Is.Not.Null); } - if (type == typeof(PageWithDependencyAndMultipleConstructors)) + if (pageType == typeof(PageWithDependencyAndMultipleConstructors)) { Assert.IsInstanceOf(page); var testPage = page as PageWithDependencyAndMultipleConstructors; @@ -668,7 +668,7 @@ public async Task GlobalRouteWithDependencyResolution(Type typeForRouteName, Typ Assert.That(testPage.OtherTestDependency, Is.Null); } - if (type == typeof(PageWithUnregisteredDependencyAndParameterlessConstructor)) + if (pageType == typeof(PageWithUnregisteredDependencyAndParameterlessConstructor)) { Assert.IsInstanceOf(page); }