From b9ee824c1e196cb46798b24682f29edbc9ce2059 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 24 May 2023 14:11:28 -0500 Subject: [PATCH] Enable AOT compatibility for Yarp.Telemetry.Consumption (#2146) * Enable AOT compatibility for Yarp.Telemetry.Consumption Also fix a simple warning in Yarp.Kubernetes.Controller. The rest of the warnings in this project will be addressed in https://github.com/microsoft/reverse-proxy/issues/2145. * Fix TryAddSingleton warning that isn't caught by the Roslyn analyzer. See https://github.com/dotnet/runtime/issues/86720 for why the warning isn't being raised. --- .../KubernetesReverseProxyServiceCollectionExtensions.cs | 3 ++- src/TelemetryConsumption/TelemetryConsumptionExtensions.cs | 5 +++-- src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Kubernetes.Controller/Management/KubernetesReverseProxyServiceCollectionExtensions.cs b/src/Kubernetes.Controller/Management/KubernetesReverseProxyServiceCollectionExtensions.cs index 241e70a64..530973f61 100644 --- a/src/Kubernetes.Controller/Management/KubernetesReverseProxyServiceCollectionExtensions.cs +++ b/src/Kubernetes.Controller/Management/KubernetesReverseProxyServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Diagnostics.CodeAnalysis; using k8s; using k8s.Models; using Microsoft.Extensions.Configuration; @@ -122,7 +123,7 @@ public static IServiceCollection RegisterResourceInformer(t /// The services. /// A field selector to constrain the resources the informer retrieves. /// IServiceCollection. - public static IServiceCollection RegisterResourceInformer(this IServiceCollection services, string fieldSelector) + public static IServiceCollection RegisterResourceInformer(this IServiceCollection services, string fieldSelector) where TResource : class, IKubernetesObject, new() where TService : IResourceInformer { diff --git a/src/TelemetryConsumption/TelemetryConsumptionExtensions.cs b/src/TelemetryConsumption/TelemetryConsumptionExtensions.cs index 90560dc24..3c0e2e275 100644 --- a/src/TelemetryConsumption/TelemetryConsumptionExtensions.cs +++ b/src/TelemetryConsumption/TelemetryConsumptionExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection.Extensions; using Yarp.Telemetry.Consumption; @@ -86,7 +87,7 @@ public static IServiceCollection AddTelemetryConsumer(this IServiceCollection se /// /// Registers a singleton for every I*TelemetryConsumer interface it implements. /// - public static IServiceCollection AddTelemetryConsumer(this IServiceCollection services) + public static IServiceCollection AddTelemetryConsumer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConsumer>(this IServiceCollection services) where TConsumer : class { var implementsAny = false; @@ -201,7 +202,7 @@ public static IServiceCollection AddMetricsConsumer(this IServiceCollection serv /// /// Registers a consumer singleton for every IMetricsConsumer interface it implements. /// - public static IServiceCollection AddMetricsConsumer(this IServiceCollection services) + public static IServiceCollection AddMetricsConsumer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConsumer>(this IServiceCollection services) where TConsumer : class { var implementsAny = false; diff --git a/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj b/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj index 6ffe2ab29..110c943ea 100644 --- a/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj +++ b/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj @@ -6,6 +6,7 @@ Library Yarp.Telemetry.Consumption enable + true README.md