@@ -52,6 +52,8 @@ public static IServiceCollection AddModEndpointsCoreFromAssembly(
5252
5353 services . TryAddScoped < IComponentDiscriminator , ComponentDiscriminator > ( ) ;
5454
55+ ComponentRegistryAccessor . Instance . Initialize ( ) ;
56+
5557 return services
5658 . AddRouteGroupsCoreFromAssembly ( assembly , options )
5759 . AddEndpointsCoreFromAssembly ( assembly , options ) ;
@@ -80,7 +82,7 @@ private static IServiceCollection AddRouteGroupsCoreFromAssembly(
8082 . ToArray ( ) ;
8183
8284 services . TryAddEnumerable ( serviceDescriptors ) ;
83- ComponentRegistry . Instance . TryAddRouteGroups ( routeGroupTypes ) ;
85+ ComponentRegistryAccessor . Instance . Registry ? . TryAddRouteGroups ( routeGroupTypes ) ;
8486
8587 return services ;
8688 }
@@ -161,12 +163,13 @@ static void AddServiceEndpoint(
161163 }
162164 }
163165 services . Add ( descriptor ) ;
166+ ComponentRegistryAccessor . Instance . Registry ? . AddEndpoint ( requestType , endpointType ) ;
164167 }
165168 else
166169 {
167170 services . TryAdd ( descriptor ) ;
171+ ComponentRegistryAccessor . Instance . Registry ? . TryAddEndpoint ( requestType , endpointType ) ;
168172 }
169- ComponentRegistry . Instance . TryAddEndpoint ( requestType , endpointType ) ;
170173 }
171174
172175 static void AddEndpoint (
@@ -179,7 +182,7 @@ static void AddEndpoint(
179182 endpointType ,
180183 endpointType ,
181184 options . EndpointLifetime ) ) ;
182- ComponentRegistry . Instance . TryAddEndpoint ( endpointType , endpointType ) ;
185+ ComponentRegistryAccessor . Instance . Registry ? . TryAddEndpoint ( endpointType , endpointType ) ;
183186 }
184187
185188 static Type [ ] GetGenericArgumentsOfBase ( Type derivedType , Type baseType )
@@ -238,8 +241,14 @@ public static WebApplication MapModEndpointsCore(
238241 IEndpointRouteBuilder builder = app ;
239242 using ( var scope = builder . ServiceProvider . CreateScope ( ) )
240243 {
241- var routeGroups = ComponentRegistry . Instance . GetRouteGroups ( ) . Select ( t => RuntimeHelpers . GetUninitializedObject ( t ) as IRouteGroupConfigurator ) . Where ( i => i is not null ) . Select ( i => i ! ) ; ;
242- var endpoints = ComponentRegistry . Instance . GetEndpoints ( ) . Select ( t => RuntimeHelpers . GetUninitializedObject ( t ) as IEndpointConfigurator ) . Where ( i => i is not null ) . Select ( i => i ! ) ;
244+ var routeGroups = ComponentRegistryAccessor . Instance . Registry ? . GetRouteGroups ( )
245+ . Select ( t => RuntimeHelpers . GetUninitializedObject ( t ) as IRouteGroupConfigurator )
246+ . Where ( i => i is not null )
247+ . Select ( i => i ! ) ?? [ ] ;
248+ var endpoints = ComponentRegistryAccessor . Instance . Registry ? . GetEndpoints ( )
249+ . Select ( t => RuntimeHelpers . GetUninitializedObject ( t ) as IEndpointConfigurator )
250+ . Where ( i => i is not null )
251+ . Select ( i => i ! ) ?? [ ] ;
243252
244253 //Items that don't have a membership to any route group or
245254 //items that have a membership to root route group (items at root)
0 commit comments