using System; using Elsa; using Elsa.AutoMapper.Extensions; using Elsa.Models; using Elsa.Server.GraphQL; using Elsa.Server.GraphQL.Mapping; using Elsa.Server.GraphQL.Mutations; using Elsa.Server.GraphQL.Queries; using Elsa.Server.GraphQL.Services; using GraphQL.NodaTime; using GraphQL.Server; using GraphQL.Types; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection { public static class GraphQLServiceCollectionExtensions { public static ElsaBuilder AddGraphQL(this ElsaBuilder builder, Action configure = null) { var services = builder.Services; services .AddScoped() .AddSingleton() .AddSingleton>() .AddQueryProvider() .AddQueryProvider() .AddQueryProvider() .AddMutationProvider() .AddMutationProvider() .AddMutationProvider() .AddMutationProvider() .AddMutationProvider() .AddAutoMapperProfile(ServiceLifetime.Singleton) .AddLogging(); var graphQLOptions = new GraphQLOptions(); configure?.Invoke(graphQLOptions); services .AddGraphQL(graphQLOptions) .AddGraphTypes(ServiceLifetime.Scoped); return builder; } public static IServiceCollection AddMutationProvider(this IServiceCollection services) where T : class, IMutationProvider { return services.AddScoped(); } public static IServiceCollection AddQueryProvider(this IServiceCollection services) where T : class, IQueryProvider { return services.AddScoped(); } } }