-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
OperationContext.Pooling.cs
68 lines (62 loc) · 2.09 KB
/
OperationContext.Pooling.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using HotChocolate.Fetching;
using Microsoft.Extensions.ObjectPool;
using static HotChocolate.Execution.ThrowHelper;
namespace HotChocolate.Execution.Processing
{
internal sealed partial class OperationContext
{
private readonly ExecutionContext _executionContext;
private readonly ResultHelper _resultHelper;
private IRequestContext _requestContext = default!;
private IPreparedOperation _operation = default!;
private IVariableValueCollection _variables = default!;
private IServiceProvider _services = default!;
private object? _rootValue;
private bool _isPooled = true;
public OperationContext(
ObjectPool<ResolverTask> resolverTaskPool,
ResultPool resultPool)
{
_executionContext = new ExecutionContext(this, resolverTaskPool);
_resultHelper = new ResultHelper(resultPool);
}
public bool IsPooled => _isPooled;
public void Initialize(
IRequestContext requestContext,
IServiceProvider scopedServices,
IBatchDispatcher batchDispatcher,
IPreparedOperation operation,
object? rootValue,
IVariableValueCollection variables)
{
_requestContext = requestContext;
_executionContext.Initialize(
batchDispatcher,
requestContext.RequestAborted);
_operation = operation;
_variables = variables;
_services = scopedServices;
_rootValue = rootValue;
_isPooled = false;
}
public void Clean()
{
_executionContext.Clean();
_resultHelper.Clear();
_requestContext = default!;
_operation = default!;
_variables = default!;
_services = default!;
_rootValue = null;
_isPooled = true;
}
private void AssertNotPooled()
{
if (_isPooled)
{
throw Object_Returned_To_Pool();
}
}
}
}