Răsfoiți Sursa

Ignore identical types when loading routable components (#39129)

* Ignore identical types when loading routable components

Instead of iterating over the list of types all the time, do a simple check if the additional assembly is the same as the app assembly and skip it.

Fixes #38882
Daniel Hottmeyer 4 ani în urmă
părinte
comite
db03aaa88e

+ 5 - 1
src/Components/Components/src/Routing/RouteTableFactory.cs

@@ -44,7 +44,11 @@ internal static class RouteTableFactory
         {
             foreach (var assembly in routeKey.AdditionalAssemblies)
             {
-                GetRouteableComponents(routeableComponents, assembly);
+                // We don't need process the assembly if it's the app assembly.
+                if (assembly != routeKey.AppAssembly)
+                {
+                    GetRouteableComponents(routeableComponents, assembly);
+                }
             }
         }
 

+ 10 - 0
src/Components/Components/test/Routing/RouteTableFactoryTests.cs

@@ -51,6 +51,16 @@ public class RouteTableFactoryTests
         Assert.NotSame(routes1, routes2);
     }
 
+    [Fact]
+    public void IgnoresIdenticalTypes()
+    {
+        // Arrange & Act
+        var routes = RouteTableFactory.Create(new RouteKey(GetType().Assembly, new[] { GetType().Assembly }));
+
+        // Assert
+        Assert.Equal(routes.Routes.GroupBy(x => x.Handler).Count(), routes.Routes.Length);
+    }
+
     [Fact]
     public void CanDiscoverRoute()
     {