Skip to content

Commit

Permalink
Enable AOT compatibility for Yarp.Telemetry.Consumption (#2146)
Browse files Browse the repository at this point in the history
* 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 #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.
  • Loading branch information
eerhardt committed May 24, 2023
1 parent 7ef8164 commit b9ee824
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using k8s;
using k8s.Models;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -122,7 +123,7 @@ public static IServiceCollection AddKubernetesControllerRuntime(this IServiceCol
/// <param name="services">The services.</param>
/// <param name="fieldSelector">A field selector to constrain the resources the informer retrieves.</param>
/// <returns>IServiceCollection.</returns>
public static IServiceCollection RegisterResourceInformer<TResource, TService>(this IServiceCollection services, string fieldSelector)
public static IServiceCollection RegisterResourceInformer<TResource, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TService>(this IServiceCollection services, string fieldSelector)
where TResource : class, IKubernetesObject<V1ObjectMeta>, new()
where TService : IResourceInformer<TResource>
{
Expand Down
5 changes: 3 additions & 2 deletions src/TelemetryConsumption/TelemetryConsumptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Yarp.Telemetry.Consumption;

Expand Down Expand Up @@ -86,7 +87,7 @@ public static IServiceCollection AddTelemetryConsumer(this IServiceCollection se
/// <summary>
/// Registers a <typeparamref name="TConsumer"/> singleton for every I*TelemetryConsumer interface it implements.
/// </summary>
public static IServiceCollection AddTelemetryConsumer<TConsumer>(this IServiceCollection services)
public static IServiceCollection AddTelemetryConsumer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConsumer>(this IServiceCollection services)
where TConsumer : class
{
var implementsAny = false;
Expand Down Expand Up @@ -201,7 +202,7 @@ public static IServiceCollection AddMetricsConsumer(this IServiceCollection serv
/// <summary>
/// Registers a consumer singleton for every IMetricsConsumer interface it implements.
/// </summary>
public static IServiceCollection AddMetricsConsumer<TConsumer>(this IServiceCollection services)
public static IServiceCollection AddMetricsConsumer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConsumer>(this IServiceCollection services)
where TConsumer : class
{
var implementsAny = false;
Expand Down
1 change: 1 addition & 0 deletions src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Yarp.Telemetry.Consumption</RootNamespace>
<Nullable>enable</Nullable>
<IsAotCompatible>true</IsAotCompatible>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand Down

0 comments on commit b9ee824

Please sign in to comment.