Skip to content

Commit e28a43f

Browse files
authored
fix: Fixes missing constructor in trimmed builds (#1970)
Closes #1969
1 parent bb406e8 commit e28a43f

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/Grpc.Net.ClientFactory/GrpcClientServiceExtensions.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public static class GrpcClientServiceExtensions
5353
/// <typeparamref name="TClient"/> as the service type.
5454
/// </para>
5555
/// </remarks>
56-
public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection services)
56+
public static IHttpClientBuilder AddGrpcClient<
57+
#if NET5_0_OR_GREATER
58+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
59+
#endif
60+
TClient>(this IServiceCollection services)
5761
where TClient : class
5862
{
5963
if (services == null)
@@ -89,7 +93,11 @@ public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection
8993
/// <typeparamref name="TClient"/> as the service type.
9094
/// </para>
9195
/// </remarks>
92-
public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection services, Action<GrpcClientFactoryOptions> configureClient)
96+
public static IHttpClientBuilder AddGrpcClient<
97+
#if NET5_0_OR_GREATER
98+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
99+
#endif
100+
TClient>(this IServiceCollection services, Action<GrpcClientFactoryOptions> configureClient)
93101
where TClient : class
94102
{
95103
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
@@ -124,7 +132,11 @@ public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection
124132
/// a reference to a scoped service provider that shares the lifetime of the handler being constructed.
125133
/// </para>
126134
/// </remarks>
127-
public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection services, Action<IServiceProvider, GrpcClientFactoryOptions> configureClient)
135+
public static IHttpClientBuilder AddGrpcClient<
136+
#if NET5_0_OR_GREATER
137+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
138+
#endif
139+
TClient>(this IServiceCollection services, Action<IServiceProvider, GrpcClientFactoryOptions> configureClient)
128140
where TClient : class
129141
{
130142
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
@@ -154,7 +166,11 @@ public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection
154166
/// <typeparamref name="TClient"/> as the service type.
155167
/// </para>
156168
/// </remarks>
157-
public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection services, string name)
169+
public static IHttpClientBuilder AddGrpcClient<
170+
#if NET5_0_OR_GREATER
171+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
172+
#endif
173+
TClient>(this IServiceCollection services, string name)
158174
where TClient : class
159175
{
160176
if (services == null)
@@ -193,7 +209,11 @@ public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection
193209
/// <typeparamref name="TClient"/> as the service type.
194210
/// </para>
195211
/// </remarks>
196-
public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection services, string name, Action<GrpcClientFactoryOptions> configureClient)
212+
public static IHttpClientBuilder AddGrpcClient<
213+
#if NET5_0_OR_GREATER
214+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
215+
#endif
216+
TClient>(this IServiceCollection services, string name, Action<GrpcClientFactoryOptions> configureClient)
197217
where TClient : class
198218
{
199219
if (services == null)
@@ -243,7 +263,11 @@ public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection
243263
/// a reference to a scoped service provider that shares the lifetime of the handler being constructed.
244264
/// </para>
245265
/// </remarks>
246-
public static IHttpClientBuilder AddGrpcClient<TClient>(this IServiceCollection services, string name, Action<IServiceProvider, GrpcClientFactoryOptions> configureClient)
266+
public static IHttpClientBuilder AddGrpcClient<
267+
#if NET5_0_OR_GREATER
268+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
269+
#endif
270+
TClient>(this IServiceCollection services, string name, Action<IServiceProvider, GrpcClientFactoryOptions> configureClient)
247271
where TClient : class
248272
{
249273
if (services == null)

0 commit comments

Comments
 (0)