Skip to content

Commit f385e6f

Browse files
authored
Expose Services within GraphQLBuilder (graphql-dotnet#2607)
1 parent 2e616d0 commit f385e6f

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/GraphQL.ApiTests/GraphQL.MicrosoftDI.approved.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ namespace GraphQL.MicrosoftDI
5151
public void ResolveAsync(System.Func<GraphQL.Builders.IResolveConnectionContext<TSourceType>, T1, T2, T3, T4, T5, System.Threading.Tasks.Task<TReturnType>> resolver) { }
5252
public GraphQL.MicrosoftDI.ConnectionResolverBuilder<TSourceType, TReturnType, T1, T2, T3, T4, T5> WithScope() { }
5353
}
54+
public class GraphQLBuilder : GraphQL.DI.GraphQLBuilderBase
55+
{
56+
public GraphQLBuilder(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { }
57+
public Microsoft.Extensions.DependencyInjection.IServiceCollection Services { get; }
58+
public override GraphQL.DI.IGraphQLBuilder Configure<TOptions>(System.Action<TOptions, System.IServiceProvider>? action = null)
59+
where TOptions : class, new () { }
60+
public override GraphQL.DI.IGraphQLBuilder Register(System.Type serviceType, object implementationInstance) { }
61+
public override GraphQL.DI.IGraphQLBuilder Register(System.Type serviceType, System.Func<System.IServiceProvider, object> implementationFactory, GraphQL.DI.ServiceLifetime serviceLifetime) { }
62+
public override GraphQL.DI.IGraphQLBuilder Register(System.Type serviceType, System.Type implementationType, GraphQL.DI.ServiceLifetime serviceLifetime) { }
63+
public override GraphQL.DI.IGraphQLBuilder TryRegister(System.Type serviceType, object implementationInstance) { }
64+
public override GraphQL.DI.IGraphQLBuilder TryRegister(System.Type serviceType, System.Func<System.IServiceProvider, object> implementationFactory, GraphQL.DI.ServiceLifetime serviceLifetime) { }
65+
public override GraphQL.DI.IGraphQLBuilder TryRegister(System.Type serviceType, System.Type implementationType, GraphQL.DI.ServiceLifetime serviceLifetime) { }
66+
}
5467
public static class GraphQLBuilderExtensions
5568
{
5669
public static GraphQL.DI.IGraphQLBuilder AddGraphQL(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) { }

src/GraphQL.MicrosoftDI/GraphQLBuilder.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ namespace GraphQL.MicrosoftDI
1414
/// An implementation of <see cref="IGraphQLBuilder"/> which uses the Microsoft dependency injection framework
1515
/// to register services and configure options.
1616
/// </summary>
17-
internal class GraphQLBuilder : GraphQLBuilderBase
17+
public class GraphQLBuilder : GraphQLBuilderBase
1818
{
19-
private readonly IServiceCollection _services;
19+
/// <summary>
20+
/// Returns the underlying <see cref="IServiceCollection"/> of this builder.
21+
/// </summary>
22+
public IServiceCollection Services { get; }
23+
2024
/// <summary>
2125
/// Initializes a new instance for the specified service collection.
2226
/// </summary>
@@ -25,7 +29,7 @@ internal class GraphQLBuilder : GraphQLBuilderBase
2529
/// </remarks>
2630
public GraphQLBuilder(IServiceCollection services)
2731
{
28-
_services = services ?? throw new ArgumentNullException(nameof(services));
32+
Services = services ?? throw new ArgumentNullException(nameof(services));
2933
services.AddOptions();
3034
Initialize();
3135
}
@@ -59,7 +63,7 @@ public override IGraphQLBuilder Register(Type serviceType, Func<IServiceProvider
5963
if (implementationFactory == null)
6064
throw new ArgumentNullException(nameof(implementationFactory));
6165

62-
_services.Add(new ServiceDescriptor(serviceType, implementationFactory, TranslateLifetime(serviceLifetime)));
66+
Services.Add(new ServiceDescriptor(serviceType, implementationFactory, TranslateLifetime(serviceLifetime)));
6367
return this;
6468
}
6569

@@ -71,7 +75,7 @@ public override IGraphQLBuilder Register(Type serviceType, Type implementationTy
7175
if (implementationType == null)
7276
throw new ArgumentNullException(nameof(implementationType));
7377

74-
_services.Add(new ServiceDescriptor(serviceType, implementationType, TranslateLifetime(serviceLifetime)));
78+
Services.Add(new ServiceDescriptor(serviceType, implementationType, TranslateLifetime(serviceLifetime)));
7579
return this;
7680
}
7781

@@ -83,7 +87,7 @@ public override IGraphQLBuilder Register(Type serviceType, object implementation
8387
if (implementationInstance == null)
8488
throw new ArgumentNullException(nameof(implementationInstance));
8589

86-
_services.Add(new ServiceDescriptor(serviceType, implementationInstance));
90+
Services.Add(new ServiceDescriptor(serviceType, implementationInstance));
8791
return this;
8892
}
8993

@@ -95,7 +99,7 @@ public override IGraphQLBuilder TryRegister(Type serviceType, Func<IServiceProvi
9599
if (implementationFactory == null)
96100
throw new ArgumentNullException(nameof(implementationFactory));
97101

98-
_services.TryAdd(new ServiceDescriptor(serviceType, implementationFactory, TranslateLifetime(serviceLifetime)));
102+
Services.TryAdd(new ServiceDescriptor(serviceType, implementationFactory, TranslateLifetime(serviceLifetime)));
99103
return this;
100104
}
101105

@@ -107,7 +111,7 @@ public override IGraphQLBuilder TryRegister(Type serviceType, Type implementatio
107111
if (implementationType == null)
108112
throw new ArgumentNullException(nameof(implementationType));
109113

110-
_services.TryAdd(new ServiceDescriptor(serviceType, implementationType, TranslateLifetime(serviceLifetime)));
114+
Services.TryAdd(new ServiceDescriptor(serviceType, implementationType, TranslateLifetime(serviceLifetime)));
111115
return this;
112116
}
113117

@@ -119,7 +123,7 @@ public override IGraphQLBuilder TryRegister(Type serviceType, object implementat
119123
if (implementationInstance == null)
120124
throw new ArgumentNullException(nameof(implementationInstance));
121125

122-
_services.TryAdd(new ServiceDescriptor(serviceType, implementationInstance));
126+
Services.TryAdd(new ServiceDescriptor(serviceType, implementationInstance));
123127
return this;
124128
}
125129
}

0 commit comments

Comments
 (0)