| File: Infrastructure\IE2EServiceOverrideResolver.cs | Web Access |
| Project: src\aspnetcore\src\Components\Testing\src\Microsoft.AspNetCore.Components.Testing.csproj (Microsoft.AspNetCore.Components.Testing) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Components.Testing.Infrastructure; /// <summary> /// Resolves service override methods by type name and method name without reflection. /// Implementations are source-generated by <c>Microsoft.AspNetCore.Components.Testing.Generators</c> /// in each test assembly that calls /// <see cref="ServerStartOptions.ConfigureServices{T}(string)"/>. /// </summary> /// <remarks> /// <para> /// The source generator detects <c>ConfigureServices<T>("MethodName")</c> /// call sites at compile time, validates the method signature, and emits a /// <c>ServiceOverrideResolver</c> that maps (type name, method name) pairs to /// direct delegate references — eliminating reflection at runtime. /// </para> /// <para> /// <see cref="TestReadinessHostingStartup"/> discovers the generated resolver /// in the test assembly and calls <see cref="TryResolve"/> before falling back /// to reflection for any unresolved overrides. /// </para> /// </remarks> public interface IE2EServiceOverrideResolver { /// <summary> /// Attempts to resolve a service override method by its assembly-qualified /// type name and method name. /// </summary> /// <param name="assemblyQualifiedTypeName"> /// The assembly-qualified name of the type containing the override method /// (as set by <see cref="ServerStartOptions.ConfigureServices{T}(string)"/>). /// </param> /// <param name="methodName"> /// The name of the static method to invoke. /// </param> /// <returns> /// A delegate that calls the override method directly, or <c>null</c> if the /// (type, method) pair was not detected at compile time. /// </returns> Action<IServiceCollection>? TryResolve(string assemblyQualifiedTypeName, string methodName); }