diff --git a/src/HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/OpenApiRequestExecutorBuilderExtensions.cs b/src/HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/OpenApiRequestExecutorBuilderExtensions.cs new file mode 100644 index 00000000000..e5a7c260800 --- /dev/null +++ b/src/HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/OpenApiRequestExecutorBuilderExtensions.cs @@ -0,0 +1,174 @@ +using System.Diagnostics.CodeAnalysis; +using HotChocolate.Execution.Configuration; +using HotChocolate.Adapters.OpenApi; +using Microsoft.Extensions.DependencyInjection.Extensions; + +// ReSharper disable once CheckNamespace +namespace Microsoft.Extensions.DependencyInjection; + +public static class OpenApiRequestExecutorBuilderExtensions +{ + /// + /// Adds an OpenAPI definition storage to the gateway. + /// + /// + /// The . + /// + /// + /// The OpenAPI definition storage instance. + /// + /// + /// A function that is called to determine if the storage should be registered or not. + /// If true is returned, the storage will not be registered. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The is null. + /// + /// + /// The is null. + /// + /// + /// The passed to the + /// is for the application services. + /// + public static IRequestExecutorBuilder AddOpenApiDefinitionStorage( + this IRequestExecutorBuilder builder, + IOpenApiDefinitionStorage storage, + Func? skipIf = null) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(storage); + + builder.AddOpenApiDefinitionStorageCore(skipIf); + + builder.Services.AddKeyedSingleton(builder.Name, storage); + + return builder; + } + + /// + /// Adds an OpenAPI definition storage to the gateway. + /// + /// + /// The . + /// + /// + /// A function that is called to determine if the storage should be registered or not. + /// If true is returned, the storage will not be registered. + /// + /// + /// The type of the OpenAPI definition storage. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The is null. + /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + ///
+ /// The passed to the + /// is for the application services. + ///
+ public static IRequestExecutorBuilder AddOpenApiDefinitionStorage< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( + this IRequestExecutorBuilder builder, + Func? skipIf = null) + where T : class, IOpenApiDefinitionStorage + { + ArgumentNullException.ThrowIfNull(builder); + + builder.AddOpenApiDefinitionStorageCore(skipIf); + + builder.Services.AddKeyedSingleton(builder.Name); + + return builder; + } + + /// + /// Adds an OpenAPI definition storage to the gateway. + /// + /// + /// The . + /// + /// + /// The factory to create the OpenAPI definition storage. + /// + /// + /// A function that is called to determine if the storage should be registered or not. + /// If true is returned, the storage will not be registered. + /// + /// + /// The type of the OpenAPI definition storage. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The is null. + /// + /// + /// The is null. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + ///
+ /// The passed to the + /// is for the application services. + ///
+ public static IRequestExecutorBuilder AddOpenApiDefinitionStorage< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( + this IRequestExecutorBuilder builder, + Func factory, + Func? skipIf = null) + where T : class, IOpenApiDefinitionStorage + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(factory); + + builder.AddOpenApiDefinitionStorageCore(skipIf); + + builder.Services.AddKeyedSingleton( + builder.Name, + (sp, _) => factory(sp)); + + return builder; + } + + private static void AddOpenApiDefinitionStorageCore( + this IRequestExecutorBuilder builder, + Func? skipIf) + { + var schemaName = builder.Name; + + builder.Services.AddOpenApiServices(schemaName); + builder.Services.AddOpenApiAspNetCoreServices(schemaName); + + builder.ConfigureSchemaServices((_, schemaServices) => + { + schemaServices.TryAddSingleton(); + schemaServices.AddOpenApiSchemaServices(); + }); + + builder.AddWarmupTask( + factory: schemaServices => + { + var registry = schemaServices.GetRootServiceProvider() + .GetRequiredKeyedService(schemaName); + + return new OpenApiWarmupTask(registry); + }, + skipIf: skipIf); + } +} diff --git a/src/HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/RequestExecutorBuilderExtensions.cs b/src/HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/RequestExecutorBuilderExtensions.cs deleted file mode 100644 index 755f59902fd..00000000000 --- a/src/HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/RequestExecutorBuilderExtensions.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using HotChocolate.Execution.Configuration; -using HotChocolate.Adapters.OpenApi; -using Microsoft.Extensions.DependencyInjection.Extensions; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Extensions.DependencyInjection; - -public static class RequestExecutorBuilderExtensions -{ - public static IRequestExecutorBuilder AddOpenApiDefinitionStorage( - this IRequestExecutorBuilder builder, - IOpenApiDefinitionStorage storage) - { - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(storage); - - builder.AddOpenApiDefinitionStorageCore(); - - builder.Services.AddKeyedSingleton(builder.Name, storage); - - return builder; - } - - public static IRequestExecutorBuilder AddOpenApiDefinitionStorage< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( - this IRequestExecutorBuilder builder) - where T : class, IOpenApiDefinitionStorage - { - ArgumentNullException.ThrowIfNull(builder); - - builder.AddOpenApiDefinitionStorageCore(); - - builder.Services.AddKeyedSingleton(builder.Name); - - return builder; - } - - public static IRequestExecutorBuilder AddOpenApiDefinitionStorage< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( - this IRequestExecutorBuilder builder, - Func factory) - where T : class, IOpenApiDefinitionStorage - { - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(factory); - - builder.AddOpenApiDefinitionStorageCore(); - - builder.Services.AddKeyedSingleton( - builder.Name, - (sp, _) => factory(sp)); - - return builder; - } - - private static void AddOpenApiDefinitionStorageCore(this IRequestExecutorBuilder builder) - { - var schemaName = builder.Name; - - builder.Services.AddOpenApiServices(schemaName); - builder.Services.AddOpenApiAspNetCoreServices(schemaName); - - builder.ConfigureSchemaServices((_, schemaServices) => - { - schemaServices.TryAddSingleton(); - schemaServices.AddOpenApiSchemaServices(); - }); - - builder.AddWarmupTask(schemaServices => - { - var registry = schemaServices.GetRootServiceProvider() - .GetRequiredKeyedService(schemaName); - - return new OpenApiWarmupTask(registry); - }); - } -} diff --git a/src/HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/FusionGatewayBuilderExtensions.cs b/src/HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/FusionGatewayBuilderExtensions.cs deleted file mode 100644 index fafb3a5f472..00000000000 --- a/src/HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/FusionGatewayBuilderExtensions.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using HotChocolate.Adapters.OpenApi; -using HotChocolate.Fusion.Configuration; -using Microsoft.Extensions.DependencyInjection.Extensions; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Extensions.DependencyInjection; - -public static class FusionGatewayBuilderExtensions -{ - public static IFusionGatewayBuilder AddOpenApiDefinitionStorage( - this IFusionGatewayBuilder builder, - IOpenApiDefinitionStorage storage) - { - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(storage); - - builder.AddOpenApiDefinitionStorageCore(); - - builder.Services.AddKeyedSingleton(builder.Name, storage); - - return builder; - } - - public static IFusionGatewayBuilder AddOpenApiDefinitionStorage< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( - this IFusionGatewayBuilder builder) - where T : class, IOpenApiDefinitionStorage - { - ArgumentNullException.ThrowIfNull(builder); - - builder.AddOpenApiDefinitionStorageCore(); - - builder.Services.AddKeyedSingleton(builder.Name); - - return builder; - } - - public static IFusionGatewayBuilder AddOpenApiDefinitionStorage< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( - this IFusionGatewayBuilder builder, - Func factory) - where T : class, IOpenApiDefinitionStorage - { - ArgumentNullException.ThrowIfNull(builder); - ArgumentNullException.ThrowIfNull(factory); - - builder.AddOpenApiDefinitionStorageCore(); - - builder.Services.AddKeyedSingleton( - builder.Name, - (sp, _) => factory(sp)); - - return builder; - } - - private static void AddOpenApiDefinitionStorageCore(this IFusionGatewayBuilder builder) - { - var schemaName = builder.Name; - - builder.Services.AddOpenApiServices(schemaName); - builder.Services.AddOpenApiAspNetCoreServices(schemaName); - - builder.ConfigureSchemaServices((_, schemaServices) => - { - schemaServices.TryAddSingleton(); - schemaServices.AddOpenApiSchemaServices(); - }); - - builder.AddWarmupTask(schemaServices => - { - var registry = schemaServices.GetRootServiceProvider() - .GetRequiredKeyedService(schemaName); - - return new OpenApiWarmupTask(registry); - }); - } -} diff --git a/src/HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/OpenApiFusionGatewayBuilderExtensions.cs b/src/HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/OpenApiFusionGatewayBuilderExtensions.cs new file mode 100644 index 00000000000..26e03bebd05 --- /dev/null +++ b/src/HotChocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/OpenApiFusionGatewayBuilderExtensions.cs @@ -0,0 +1,174 @@ +using System.Diagnostics.CodeAnalysis; +using HotChocolate.Adapters.OpenApi; +using HotChocolate.Fusion.Configuration; +using Microsoft.Extensions.DependencyInjection.Extensions; + +// ReSharper disable once CheckNamespace +namespace Microsoft.Extensions.DependencyInjection; + +public static class OpenApiFusionGatewayBuilderExtensions +{ + /// + /// Adds an OpenAPI definition storage to the gateway. + /// + /// + /// The . + /// + /// + /// The OpenAPI definition storage instance. + /// + /// + /// A function that is called to determine if the storage should be registered or not. + /// If true is returned, the storage will not be registered. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The is null. + /// + /// + /// The is null. + /// + /// + /// The passed to the + /// is for the application services. + /// + public static IFusionGatewayBuilder AddOpenApiDefinitionStorage( + this IFusionGatewayBuilder builder, + IOpenApiDefinitionStorage storage, + Func? skipIf = null) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(storage); + + builder.AddOpenApiDefinitionStorageCore(skipIf); + + builder.Services.AddKeyedSingleton(builder.Name, storage); + + return builder; + } + + /// + /// Adds an OpenAPI definition storage to the gateway. + /// + /// + /// The . + /// + /// + /// A function that is called to determine if the storage should be registered or not. + /// If true is returned, the storage will not be registered. + /// + /// + /// The type of the OpenAPI definition storage. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The is null. + /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + ///
+ /// The passed to the + /// is for the application services. + ///
+ public static IFusionGatewayBuilder AddOpenApiDefinitionStorage< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( + this IFusionGatewayBuilder builder, + Func? skipIf = null) + where T : class, IOpenApiDefinitionStorage + { + ArgumentNullException.ThrowIfNull(builder); + + builder.AddOpenApiDefinitionStorageCore(skipIf); + + builder.Services.AddKeyedSingleton(builder.Name); + + return builder; + } + + /// + /// Adds an OpenAPI definition storage to the gateway. + /// + /// + /// The . + /// + /// + /// The factory to create the OpenAPI definition storage. + /// + /// + /// A function that is called to determine if the storage should be registered or not. + /// If true is returned, the storage will not be registered. + /// + /// + /// The type of the OpenAPI definition storage. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The is null. + /// + /// + /// The is null. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + ///
+ /// The passed to the + /// is for the application services. + ///
+ public static IFusionGatewayBuilder AddOpenApiDefinitionStorage< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( + this IFusionGatewayBuilder builder, + Func factory, + Func? skipIf = null) + where T : class, IOpenApiDefinitionStorage + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(factory); + + builder.AddOpenApiDefinitionStorageCore(skipIf); + + builder.Services.AddKeyedSingleton( + builder.Name, + (sp, _) => factory(sp)); + + return builder; + } + + private static void AddOpenApiDefinitionStorageCore( + this IFusionGatewayBuilder builder, + Func? skipIf) + { + var schemaName = builder.Name; + + builder.Services.AddOpenApiServices(schemaName); + builder.Services.AddOpenApiAspNetCoreServices(schemaName); + + builder.ConfigureSchemaServices((_, schemaServices) => + { + schemaServices.TryAddSingleton(); + schemaServices.AddOpenApiSchemaServices(); + }); + + builder.AddWarmupTask( + factory: schemaServices => + { + var registry = schemaServices.GetRootServiceProvider() + .GetRequiredKeyedService(schemaName); + + return new OpenApiWarmupTask(registry); + }, + skipIf: skipIf); + } +} diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Http.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Http.cs index a25b3e94caa..eb57a3957a3 100644 --- a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Http.cs +++ b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Http.cs @@ -23,6 +23,11 @@ public static partial class HotChocolateAspNetCoreServiceCollectionExtensions /// /// Returns the so that configuration can be chained. /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IRequestExecutorBuilder AddHttpRequestInterceptor( this IRequestExecutorBuilder builder) where T : class, IHttpRequestInterceptor @@ -49,6 +54,14 @@ public static IRequestExecutorBuilder AddHttpRequestInterceptor( /// /// Returns the so that configuration can be chained. /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IRequestExecutorBuilder AddHttpRequestInterceptor( this IRequestExecutorBuilder builder, Func factory) diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Subscriptions.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Subscriptions.cs index 8b63e85b247..4e25af4f8c7 100644 --- a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Subscriptions.cs +++ b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Subscriptions.cs @@ -23,6 +23,11 @@ public static partial class HotChocolateAspNetCoreServiceCollectionExtensions /// /// Returns the so that configuration can be chained. /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IRequestExecutorBuilder AddSocketSessionInterceptor( this IRequestExecutorBuilder builder) where T : class, ISocketSessionInterceptor => @@ -45,6 +50,14 @@ public static IRequestExecutorBuilder AddSocketSessionInterceptor( /// /// Returns the so that configuration can be chained. /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IRequestExecutorBuilder AddSocketSessionInterceptor( this IRequestExecutorBuilder builder, Func factory) diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Warmup.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Warmup.cs index c2243df1758..83d77a7d2be 100644 --- a/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Warmup.cs +++ b/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/HotChocolateAspNetCoreServiceCollectionExtensions.Warmup.cs @@ -17,7 +17,8 @@ public static partial class HotChocolateAspNetCoreServiceCollectionExtensions /// The warmup delegate to execute. /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// Returns the so that configuration can be chained. @@ -28,10 +29,14 @@ public static partial class HotChocolateAspNetCoreServiceCollectionExtensions /// /// The is null. /// + /// + /// The passed to the + /// is for the application services. + /// public static IRequestExecutorBuilder AddWarmupTask( this IRequestExecutorBuilder builder, Func warmupFunc, - bool skipIf = false) + Func? skipIf = null) { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(warmupFunc); @@ -49,7 +54,8 @@ public static IRequestExecutorBuilder AddWarmupTask( /// The warmup task to execute. /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// Returns the so that configuration can be chained. @@ -60,20 +66,27 @@ public static IRequestExecutorBuilder AddWarmupTask( /// /// The is null. /// + /// + /// The passed to the + /// is for the application services. + /// public static IRequestExecutorBuilder AddWarmupTask( this IRequestExecutorBuilder builder, IRequestExecutorWarmupTask warmupTask, - bool skipIf = false) + Func? skipIf = null) { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(warmupTask); - if (skipIf) + return builder.ConfigureSchemaServices((applicationServices, sc) => { - return builder; - } + var shouldSkip = skipIf?.Invoke(applicationServices) ?? false; - return builder.ConfigureSchemaServices((_, sc) => sc.AddSingleton(warmupTask)); + if (!shouldSkip) + { + sc.AddSingleton(warmupTask); + } + }); } /// @@ -83,7 +96,8 @@ public static IRequestExecutorBuilder AddWarmupTask( /// The . /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// The warmup task to execute. @@ -94,20 +108,31 @@ public static IRequestExecutorBuilder AddWarmupTask( /// /// The is null. /// - public static IRequestExecutorBuilder AddWarmupTask<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + ///
+ /// The passed to the + /// is for the application services. + ///
+ public static IRequestExecutorBuilder AddWarmupTask< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IRequestExecutorBuilder builder, - bool skipIf = false) + Func? skipIf = null) where T : class, IRequestExecutorWarmupTask { ArgumentNullException.ThrowIfNull(builder); - if (skipIf) + builder.ConfigureSchemaServices((applicationServices, sc) => { - return builder; - } + var shouldSkip = skipIf?.Invoke(applicationServices) ?? false; - builder.ConfigureSchemaServices( - static (_, sc) => sc.AddSingleton()); + if (!shouldSkip) + { + sc.AddSingleton(); + } + }); return builder; } @@ -122,7 +147,8 @@ public static IRequestExecutorBuilder AddWarmupTask( /// The factory to create the warmup task. /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// Returns the so that configuration can be chained. @@ -133,23 +159,37 @@ public static IRequestExecutorBuilder AddWarmupTask( /// /// The is null. /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + ///
+ /// The passed to the + /// is for the application services. + ///
public static IRequestExecutorBuilder AddWarmupTask< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IRequestExecutorBuilder builder, Func factory, - bool skipIf = false) + Func? skipIf = null) where T : class, IRequestExecutorWarmupTask { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(factory); - if (skipIf) - { - return builder; - } - builder.ConfigureSchemaServices( - (_, sc) => sc.AddSingleton(factory)); + (applicationServices, sc) => + { + var shouldSkip = skipIf?.Invoke(applicationServices) ?? false; + + if (!shouldSkip) + { + sc.AddSingleton(factory); + } + }); return builder; } @@ -181,6 +221,6 @@ public static IRequestExecutorBuilder ExportSchemaOnStartup( schemaFileName ??= System.IO.Path.Combine(Environment.CurrentDirectory, "schema.graphqls"); - return builder.AddWarmupTask(new SchemaFileExporterWarmupTask(schemaFileName), skipIf); + return builder.AddWarmupTask(new SchemaFileExporterWarmupTask(schemaFileName), _ => skipIf); } } diff --git a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.ErrorFilter.cs b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.ErrorFilter.cs index b447809afa6..898abc1dfe2 100644 --- a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.ErrorFilter.cs +++ b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.ErrorFilter.cs @@ -9,6 +9,18 @@ namespace Microsoft.Extensions.DependencyInjection; public static partial class RequestExecutorBuilderExtensions { + /// + /// Adds an error filter delegate to the GraphQL configuration. + /// + /// + /// The . + /// + /// + /// A delegate that is called for each error and can modify or replace it. + /// + /// + /// Returns the so that configuration can be chained. + /// public static IRequestExecutorBuilder AddErrorFilter( this IRequestExecutorBuilder builder, Func errorFilter) @@ -21,6 +33,29 @@ public static IRequestExecutorBuilder AddErrorFilter( new FuncErrorFilterWrapper(errorFilter))); } + /// + /// Adds an error filter to the GraphQL configuration. + /// + /// + /// The . + /// + /// + /// A factory that creates the error filter instance. + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IRequestExecutorBuilder AddErrorFilter( this IRequestExecutorBuilder builder, Func factory) @@ -33,6 +68,23 @@ public static IRequestExecutorBuilder AddErrorFilter( s => s.AddSingleton(factory)); } + /// + /// Adds an error filter to the GraphQL configuration. + /// + /// + /// The . + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IRequestExecutorBuilder AddErrorFilter( this IRequestExecutorBuilder builder) where T : class, IErrorFilter diff --git a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Instrumentation.cs b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Instrumentation.cs index 52f73e4c05b..8cacd9d50ba 100644 --- a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Instrumentation.cs +++ b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Instrumentation.cs @@ -9,6 +9,26 @@ namespace Microsoft.Extensions.DependencyInjection; public static partial class RequestExecutorBuilderExtensions { + /// + /// Registers a diagnostic event listener. + /// + /// + /// The request executor builder. + /// + /// + /// The type of the diagnostic event listener. + /// + /// + /// The request executor builder. + /// + /// + /// The is not a recognized diagnostic event listener. + /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IRequestExecutorBuilder AddDiagnosticEventListener( this IRequestExecutorBuilder builder) where T : class @@ -57,6 +77,32 @@ public static IRequestExecutorBuilder AddDiagnosticEventListener( return builder; } + /// + /// Registers a diagnostic event listener. + /// + /// + /// The request executor builder. + /// + /// + /// The factory to produce the diagnostic event listener. + /// + /// + /// The type of the diagnostic event listener. + /// + /// + /// The request executor builder. + /// + /// + /// The service returned from the is not a recognized diagnostic event listener. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IRequestExecutorBuilder AddDiagnosticEventListener( this IRequestExecutorBuilder builder, Func factory) diff --git a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Optimizer.cs b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Optimizer.cs index 0d83d3c6e03..525a65c1c45 100644 --- a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Optimizer.cs +++ b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Optimizer.cs @@ -6,6 +6,23 @@ namespace Microsoft.Extensions.DependencyInjection; public static partial class RequestExecutorBuilderExtensions { + /// + /// Adds an operation compiler optimizer to the GraphQL configuration. + /// + /// + /// The . + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IRequestExecutorBuilder AddOperationCompilerOptimizer( this IRequestExecutorBuilder builder) where T : class, IOperationCompilerOptimizer @@ -16,6 +33,29 @@ public static IRequestExecutorBuilder AddOperationCompilerOptimizer( return builder; } + /// + /// Adds an operation compiler optimizer to the GraphQL configuration. + /// + /// + /// The . + /// + /// + /// A factory that creates the optimizer instance. + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IRequestExecutorBuilder AddOperationCompilerOptimizer( this IRequestExecutorBuilder builder, Func factory) diff --git a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.TransactionScope.cs b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.TransactionScope.cs index f274846faf3..2215856cd79 100644 --- a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.TransactionScope.cs +++ b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.TransactionScope.cs @@ -22,6 +22,11 @@ public static partial class RequestExecutorBuilderExtensions /// /// The is null. /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IRequestExecutorBuilder AddTransactionScopeHandler( this IRequestExecutorBuilder builder) where T : class, ITransactionScopeHandler @@ -53,6 +58,14 @@ public static IRequestExecutorBuilder AddTransactionScopeHandler( /// The request executor builder. ///
/// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IRequestExecutorBuilder AddTransactionScopeHandler( this IRequestExecutorBuilder builder, Func factory) diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.AspNetCore/DependencyInjection/AspNetCoreFusionGatewayBuilderExtensions.HttpRequestInterceptor.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.AspNetCore/DependencyInjection/AspNetCoreFusionGatewayBuilderExtensions.HttpRequestInterceptor.cs index 757e00d8660..b70beec7249 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.AspNetCore/DependencyInjection/AspNetCoreFusionGatewayBuilderExtensions.HttpRequestInterceptor.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.AspNetCore/DependencyInjection/AspNetCoreFusionGatewayBuilderExtensions.HttpRequestInterceptor.cs @@ -6,6 +6,18 @@ namespace Microsoft.Extensions.DependencyInjection; public static partial class AspNetCoreFusionGatewayBuilderExtensions { + /// + /// Adds an interceptor for GraphQL over HTTP requests. + /// + /// + /// The . + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// public static IFusionGatewayBuilder AddHttpRequestInterceptor( this IFusionGatewayBuilder builder) where T : IHttpRequestInterceptor, new() @@ -20,6 +32,26 @@ public static IFusionGatewayBuilder AddHttpRequestInterceptor( }); } + /// + /// Adds an interceptor for GraphQL over HTTP requests. + /// + /// + /// The . + /// + /// + /// A factory that creates the interceptor instance. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IFusionGatewayBuilder AddHttpRequestInterceptor( this IFusionGatewayBuilder builder, Func factory) diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Diagnostics.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Diagnostics.cs index a47280ca8d6..640e79167ab 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Diagnostics.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Diagnostics.cs @@ -20,6 +20,11 @@ public static partial class CoreFusionGatewayBuilderExtensions /// /// The fusion gateway builder. /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IFusionGatewayBuilder AddDiagnosticEventListener< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IFusionGatewayBuilder builder) @@ -77,6 +82,14 @@ public static IFusionGatewayBuilder AddDiagnosticEventListener< /// /// The fusion gateway builder. /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IFusionGatewayBuilder AddDiagnosticEventListener< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IFusionGatewayBuilder builder, diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.ErrorFilter.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.ErrorFilter.cs index 014ef7d5ac9..6f07960da8a 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.ErrorFilter.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.ErrorFilter.cs @@ -9,6 +9,18 @@ namespace Microsoft.Extensions.DependencyInjection; public static partial class CoreFusionGatewayBuilderExtensions { + /// + /// Adds an error filter delegate. + /// + /// + /// The . + /// + /// + /// A delegate that is called for each error and can modify or replace it. + /// + /// + /// Returns the so that configuration can be chained. + /// public static IFusionGatewayBuilder AddErrorFilter( this IFusionGatewayBuilder builder, Func errorFilter) @@ -20,6 +32,23 @@ public static IFusionGatewayBuilder AddErrorFilter( (_, s) => s.AddSingleton(new FuncErrorFilterWrapper(errorFilter))); } + /// + /// Adds an error filter. + /// + /// + /// The . + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + /// public static IFusionGatewayBuilder AddErrorFilter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IFusionGatewayBuilder builder) where T : class, IErrorFilter @@ -31,6 +60,29 @@ public static IFusionGatewayBuilder AddErrorFilter( (sp, s) => s.AddSingleton(_ => sp.GetRequiredService())); } + /// + /// Adds an error filter. + /// + /// + /// The . + /// + /// + /// A factory that creates the error filter instance. + /// + /// + /// The implementation. + /// + /// + /// Returns the so that configuration can be chained. + /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + /// public static IFusionGatewayBuilder AddErrorFilter( this IFusionGatewayBuilder builder, Func factory) diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Warmup.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Warmup.cs index 4dc98081f7c..1de0317b986 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Warmup.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/CoreFusionGatewayBuilderExtensions.Warmup.cs @@ -17,7 +17,8 @@ public static partial class CoreFusionGatewayBuilderExtensions /// The warmup delegate to execute. /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// Returns the so that configuration can be chained. @@ -28,10 +29,14 @@ public static partial class CoreFusionGatewayBuilderExtensions /// /// The is null. /// + /// + /// The passed to the + /// is for the application services. + /// public static IFusionGatewayBuilder AddWarmupTask( this IFusionGatewayBuilder builder, Func warmupFunc, - bool skipIf = false) + Func? skipIf = null) { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(warmupFunc); @@ -49,7 +54,8 @@ public static IFusionGatewayBuilder AddWarmupTask( /// The warmup task to execute. /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// Returns the so that configuration can be chained. @@ -60,20 +66,27 @@ public static IFusionGatewayBuilder AddWarmupTask( /// /// The is null. /// + /// + /// The passed to the + /// is for the application services. + /// public static IFusionGatewayBuilder AddWarmupTask( this IFusionGatewayBuilder builder, IRequestExecutorWarmupTask warmupTask, - bool skipIf = false) + Func? skipIf = null) { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(warmupTask); - if (skipIf) + return builder.ConfigureSchemaServices((applicationServices, sc) => { - return builder; - } + var shouldSkip = skipIf?.Invoke(applicationServices) ?? false; - return builder.ConfigureSchemaServices((_, sc) => sc.AddSingleton(warmupTask)); + if (!shouldSkip) + { + sc.AddSingleton(warmupTask); + } + }); } /// @@ -83,7 +96,8 @@ public static IFusionGatewayBuilder AddWarmupTask( /// The . /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// The warmup task to execute. @@ -94,20 +108,31 @@ public static IFusionGatewayBuilder AddWarmupTask( /// /// The is null. /// + /// + /// The will be activated with the of the schema services. + /// If your needs to access application services you need to + /// make the services available in the schema services via . + ///
+ /// The passed to the + /// is for the application services. + ///
public static IFusionGatewayBuilder AddWarmupTask< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IFusionGatewayBuilder builder, - bool skipIf = false) + Func? skipIf = null) where T : class, IRequestExecutorWarmupTask { ArgumentNullException.ThrowIfNull(builder); - if (skipIf) + builder.ConfigureSchemaServices((applicationServices, sc) => { - return builder; - } + var shouldSkip = skipIf?.Invoke(applicationServices) ?? false; - builder.ConfigureSchemaServices(static (_, sc) => sc.AddSingleton()); + if (!shouldSkip) + { + sc.AddSingleton(); + } + }); return builder; } @@ -122,7 +147,8 @@ public static IFusionGatewayBuilder AddWarmupTask< /// The factory to create the warmup task. /// /// - /// If true, the warmup task will not be registered. + /// A function that is called to determine if the warmup service should be registered or not. + /// If true is returned, the warmup task will not be registered. /// /// /// Returns the so that configuration can be chained. @@ -133,23 +159,37 @@ public static IFusionGatewayBuilder AddWarmupTask< /// /// The is null. /// + /// + /// The passed to the + /// is for the schema services. If you need to access application services + /// you need to either make the services available in the schema services + /// via or use + /// + /// to access the application services from within the schema service provider. + ///
+ /// The passed to the + /// is for the application services. + ///
public static IFusionGatewayBuilder AddWarmupTask< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( this IFusionGatewayBuilder builder, Func factory, - bool skipIf = false) + Func? skipIf = null) where T : class, IRequestExecutorWarmupTask { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(factory); - if (skipIf) - { - return builder; - } - builder.ConfigureSchemaServices( - (_, sc) => sc.AddSingleton(factory)); + (applicationServices, sc) => + { + var shouldSkip = skipIf?.Invoke(applicationServices) ?? false; + + if (!shouldSkip) + { + sc.AddSingleton(factory); + } + }); return builder; }