@@ -14,6 +14,11 @@ namespace Microsoft.AspNetCore.Components;
14
14
15
15
internal sealed class ComponentFactory
16
16
{
17
+ // This switch is unsupported and will be removed in a future version.
18
+ private static readonly bool _propertyInjectionDisabled =
19
+ AppContext . TryGetSwitch ( "Microsoft.AspNetCore.Components.Unsupported.DisablePropertyInjection" , out var isDisabled ) &&
20
+ isDisabled ;
21
+
17
22
private const BindingFlags _injectablePropertyBindingFlags
18
23
= BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
19
24
@@ -82,15 +87,18 @@ public IComponent InstantiateComponent(IServiceProvider serviceProvider, [Dynami
82
87
throw new InvalidOperationException ( $ "The component activator returned a null value for a component of type { componentType . FullName } .") ;
83
88
}
84
89
85
- if ( component . GetType ( ) == componentType )
86
- {
87
- // Fast, common case: use the cached data we already looked up
88
- propertyInjector ( serviceProvider , component ) ;
89
- }
90
- else
90
+ if ( ! _propertyInjectionDisabled )
91
91
{
92
- // Uncommon case where the activator/resolver returned a different type. Needs an extra cache lookup.
93
- PerformPropertyInjection ( serviceProvider , component ) ;
92
+ if ( component . GetType ( ) == componentType )
93
+ {
94
+ // Fast, common case: use the cached data we already looked up
95
+ propertyInjector ( serviceProvider , component ) ;
96
+ }
97
+ else
98
+ {
99
+ // Uncommon case where the activator/resolver returned a different type. Needs an extra cache lookup.
100
+ PerformPropertyInjection ( serviceProvider , component ) ;
101
+ }
94
102
}
95
103
96
104
return component ;
0 commit comments