Skip to content

Commit

Permalink
Introduced TrySetServices on the request
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Mar 12, 2020
1 parent 6a994a6 commit 0055455
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Core/Abstractions/Execution/IQueryRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ IQueryRequestBuilder SetExtension(
IQueryRequestBuilder SetServices(
IServiceProvider services);

IQueryRequestBuilder TrySetServices(
IServiceProvider services);

IReadOnlyQueryRequest Create();
}
}
10 changes: 10 additions & 0 deletions src/Core/Abstractions/Execution/QueryRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public IQueryRequestBuilder SetServices(
return this;
}

public IQueryRequestBuilder TrySetServices(
IServiceProvider services)
{
if (_services is null)
{
_services = services;
}
return this;
}

public IQueryRequestBuilder SetVariableValues(
Dictionary<string, object> variableValues) =>
SetVariableValues((IDictionary<string, object>)variableValues);
Expand Down
5 changes: 2 additions & 3 deletions src/Server/AspNetCore.Abstractions/QueryMiddlewareBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ protected async Task<IReadOnlyQueryRequest> BuildRequestAsync(
{
if (!_interceptorInitialized)
{
_interceptor = services
.GetService<IQueryRequestInterceptor<HttpContext>>();
_interceptor = services.GetService<IQueryRequestInterceptor<HttpContext>>();
_interceptorInitialized = true;
}

Expand All @@ -232,7 +231,7 @@ await _interceptor.OnCreateAsync(
.ConfigureAwait(false);
}

builder.SetServices(services);
builder.TrySetServices(services);
builder.TryAddProperty(nameof(HttpContext), context);
builder.TryAddProperty(nameof(ClaimsPrincipal), context.GetUser());

Expand Down

0 comments on commit 0055455

Please sign in to comment.