Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using HotChocolate;
using HotChocolate.AspNetCore;
using HotChocolate.AspNetCore.Formatters;
Expand Down Expand Up @@ -58,6 +59,9 @@ private static IFusionGatewayBuilder AddGraphQLGatewayServerCore(
this IFusionGatewayBuilder builder,
int maxAllowedRequestSize = ServerDefaults.MaxAllowedRequestSize)
{
KeepClosedType(typeof(OptionsMonitor<GraphQLServerOptions>));
KeepClosedType(typeof(OptionsFactory<GraphQLServerOptions>));

builder.ConfigureSchemaServices((applicationServices, sc) =>
{
sc.TryAddSingleton<ITimeProvider, DefaultTimeProvider>();
Expand Down Expand Up @@ -107,6 +111,12 @@ private static IFusionGatewayBuilder AddGraphQLGatewayServerCore(
return builder;
}

// References a closed generic type that dependency injection creates at run time,
// so that a Native AOT binary contains the type.
private static void KeepClosedType(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
=> GC.KeepAlive(type);

private static IFusionGatewayBuilder AddStartupInitialization(
this IFusionGatewayBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using HotChocolate;
using HotChocolate.Execution;
using HotChocolate.Fusion.Configuration;
Expand Down Expand Up @@ -65,6 +66,9 @@ private static void AddCore(
private static void AddRequestExecutorManager(
IServiceCollection services)
{
KeepClosedType(typeof(OptionsMonitor<FusionGatewaySetup>));
KeepClosedType(typeof(OptionsFactory<FusionGatewaySetup>));

services.TryAddSingleton(
static sp => new FusionRequestExecutorManager(
sp.GetRequiredService<IOptionsMonitor<FusionGatewaySetup>>(),
Expand All @@ -79,6 +83,9 @@ private static void AddRequestExecutorManager(
private static void AddSourceSchemaScope(
IServiceCollection services)
{
KeepClosedType(typeof(OptionsMonitor<HttpClientFactoryOptions>));
KeepClosedType(typeof(OptionsFactory<HttpClientFactoryOptions>));

services.AddSingleton<ISourceSchemaClientFactory>(
static sp => new HttpSourceSchemaClientFactory(
sp.GetRequiredService<IHttpClientFactory>(),
Expand All @@ -89,6 +96,12 @@ private static void AddSourceSchemaScope(
sp.GetServices<ISourceSchemaClientFactory>().ToArray()));
}

// References a closed generic type that dependency injection creates at run time,
// so that a Native AOT binary contains the type.
private static void KeepClosedType(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
=> GC.KeepAlive(type);

private static DefaultFusionGatewayBuilder CreateBuilder(
IServiceCollection services,
string name)
Expand Down
Loading