Skip to content

Commit aa30c55

Browse files
committed
Build ServiceDiscovery library and tests against .NET Framework
This enables scenarios to use the library on .NET Framework. This is mostly done by using C# 14 new extension syntax so very little code changes were made but rather the APIs that didn't exist are added into FrameworkExtensions classes to light them up on .NET Core builds.
1 parent 410d650 commit aa30c55

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
4+
<TargetFrameworks>$(DefaultTargetFramework);net462</TargetFrameworks>
55
<IsPackable>true</IsPackable>
6-
<IsAotCompatible>true</IsAotCompatible>
6+
<IsAotCompatible Condition=" '$(TargetFramework)' != 'net462' ">true</IsAotCompatible>
77
<Description>Provides extensions to HttpClient that enable service discovery based on configuration.</Description>
88
<PackageIconFullPath>$(DefaultDotnetIconFullPath)</PackageIconFullPath>
99
</PropertyGroup>
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.Http" />
13-
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Tests"/>
14-
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Dns.Tests"/>
13+
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Tests" />
14+
<InternalsVisibleTo Include="Microsoft.Extensions.ServiceDiscovery.Dns.Tests" />
1515
</ItemGroup>
1616

1717
<ItemGroup>
1818
<ProjectReference Include="..\Microsoft.Extensions.ServiceDiscovery.Abstractions\Microsoft.Extensions.ServiceDiscovery.Abstractions.csproj" />
1919
</ItemGroup>
2020

21+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
22+
<PackageReference Include="Microsoft.Bcl.TimeProvider" />
23+
</ItemGroup>
24+
25+
<Import Project="$(SharedDir)FxPolyfills\FxPolyfills.targets" />
26+
2127
</Project>

src/Microsoft.Extensions.ServiceDiscovery/ServiceDiscoveryHttpClientBuilderExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.Extensions.DependencyInjection.Extensions;
5-
using Microsoft.Extensions.Http;
64
using Microsoft.Extensions.Options;
75
using Microsoft.Extensions.ServiceDiscovery;
86
using Microsoft.Extensions.ServiceDiscovery.Http;
97

8+
#if NET
9+
using Microsoft.Extensions.DependencyInjection.Extensions;
10+
using Microsoft.Extensions.Http;
11+
#endif
12+
1013
namespace Microsoft.Extensions.DependencyInjection;
1114

1215
/// <summary>
@@ -34,13 +37,15 @@ public static IHttpClientBuilder AddServiceDiscovery(this IHttpClientBuilder htt
3437
return new ResolvingHttpDelegatingHandler(registry, options);
3538
});
3639

40+
#if NET
3741
// Configure the HttpClient to disable gRPC load balancing.
3842
// This is done on all HttpClient instances but only impacts gRPC clients.
3943
AddDisableGrpcLoadBalancingFilter(httpClientBuilder.Services, httpClientBuilder.Name);
40-
44+
#endif
4145
return httpClientBuilder;
4246
}
4347

48+
#if NET
4449
private static void AddDisableGrpcLoadBalancingFilter(IServiceCollection services, string? name)
4550
{
4651
// A filter is used because it will always run last. This is important because the disable
@@ -86,4 +91,5 @@ public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuil
8691
};
8792
}
8893
}
94+
#endif
8995
}

0 commit comments

Comments
 (0)