diff --git a/global.json b/global.json index 7a6d1be340bd..09a4250ca45b 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.100-rc.1.25411.109", + "version": "10.0.100-rc.1.25420.111", "paths": [ ".dotnet", "$host$" @@ -8,7 +8,7 @@ "errorMessage": "The .NET SDK could not be found, run ./restore.cmd or ./restore.sh first." }, "tools": { - "dotnet": "10.0.100-rc.1.25411.109", + "dotnet": "10.0.100-rc.1.25420.111", "runtimes": { "dotnet/x86": [ "$(MicrosoftInternalRuntimeAspNetCoreTransportVersion)" diff --git a/src/Components/Components/src/ComponentFactory.cs b/src/Components/Components/src/ComponentFactory.cs index 5a6c5b5c71c8..0618c9a4d20a 100644 --- a/src/Components/Components/src/ComponentFactory.cs +++ b/src/Components/Components/src/ComponentFactory.cs @@ -14,6 +14,11 @@ namespace Microsoft.AspNetCore.Components; internal sealed class ComponentFactory { + // This switch is unsupported and will be removed in a future version. + private static readonly bool _propertyInjectionDisabled = + AppContext.TryGetSwitch("Microsoft.AspNetCore.Components.Unsupported.DisablePropertyInjection", out var isDisabled) && + isDisabled; + private const BindingFlags _injectablePropertyBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; @@ -82,15 +87,18 @@ public IComponent InstantiateComponent(IServiceProvider serviceProvider, [Dynami throw new InvalidOperationException($"The component activator returned a null value for a component of type {componentType.FullName}."); } - if (component.GetType() == componentType) - { - // Fast, common case: use the cached data we already looked up - propertyInjector(serviceProvider, component); - } - else + if (!_propertyInjectionDisabled) { - // Uncommon case where the activator/resolver returned a different type. Needs an extra cache lookup. - PerformPropertyInjection(serviceProvider, component); + if (component.GetType() == componentType) + { + // Fast, common case: use the cached data we already looked up + propertyInjector(serviceProvider, component); + } + else + { + // Uncommon case where the activator/resolver returned a different type. Needs an extra cache lookup. + PerformPropertyInjection(serviceProvider, component); + } } return component;