@@ -492,10 +492,9 @@ private static Registration CreateCrossWireRegistration(
492
492
return registration ;
493
493
}
494
494
495
- private static Func < object > BuildSingletonInstanceCreator (
496
- Type serviceType , IServiceProvider rootProvider )
495
+ private static Func < object > BuildSingletonInstanceCreator ( Type serviceType , IServiceProvider rootProvider )
497
496
{
498
- return ( ) => rootProvider . GetRequiredService ( serviceType ) ;
497
+ return ( ) => GetRequiredService ( rootProvider , serviceType ) ;
499
498
}
500
499
501
500
private static Func < object > BuildScopedInstanceCreator (
@@ -524,10 +523,28 @@ private static Func<object> BuildScopedInstanceCreator(
524
523
$ "Error resolving the cross-wired { serviceType . ToFriendlyName ( ) } . { ex . Message } ", ex ) ;
525
524
}
526
525
527
- return current . GetRequiredService ( serviceType ) ;
526
+ return GetRequiredService ( current , serviceType ) ;
528
527
} ;
529
528
}
530
529
530
+ private static object GetRequiredService ( IServiceProvider provider , Type serviceType )
531
+ {
532
+ try
533
+ {
534
+ return provider . GetRequiredService ( serviceType ) ;
535
+ }
536
+ catch ( Exception ex )
537
+ {
538
+ throw new InvalidOperationException (
539
+ $ "Failed to resolve { serviceType . ToFriendlyName ( ) } . { serviceType . ToFriendlyName ( ) } is a " +
540
+ $ "cross-wired service, meaning that Simple Injector forwarded the request the framework's " +
541
+ $ "IServiceProvider in order to get an instance. The used { provider . GetType ( ) . FullName } , " +
542
+ $ "however, failed with the following message: \" { ex . Message } \" . This error might indicate a " +
543
+ $ "misconfiguration of services in the framework's IServiceCollection.",
544
+ ex ) ;
545
+ }
546
+ }
547
+
531
548
private static ServiceDescriptor ? FindServiceDescriptor ( IServiceCollection services , Type serviceType )
532
549
{
533
550
// In case there are multiple descriptors for a given type, .NET Core will use the last
0 commit comments