Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"sdk": {
"version": "10.0.100-rc.1.25411.109",
"version": "10.0.100-rc.1.25420.111",
"paths": [
".dotnet",
"$host$"
],
"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)"
Expand Down
24 changes: 16 additions & 8 deletions src/Components/Components/src/ComponentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading