Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Keyed Service Attribute #6810

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/HotChocolate/Core/src/Abstractions/ServiceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace HotChocolate;
/// Marks a resolver parameter as a service that shall be injected by the execution engine.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public sealed class ServiceAttribute : Attribute
public class ServiceAttribute : Attribute
{
/// <summary>
/// Marks a resolver parameter as a service that shall be injected by the execution engine.
Expand All @@ -19,6 +19,28 @@ public ServiceAttribute(ServiceKind kind = ServiceKind.Default)
Kind = kind;
}

#if NET8_0_OR_GREATER
/// <summary>
/// Marks a resolver parameter as a service that shall be injected by the execution engine.
/// </summary>
/// <param name="key">
/// A key that shall be used to resolve the service.
/// </param>
/// <param name="kind">
/// The scope of the service.
/// </param>
public ServiceAttribute(string key, ServiceKind kind = ServiceKind.Default)
{
Key = key;
Kind = kind;
}

/// <summary>
/// Gets the key that shall be used to resolve the service.
/// </summary>
public string? Key { get; }
#endif

/// <summary>
/// Gets the service kind which specifies the way the service
/// shall be injected and handled by the execution engine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private static TypeReference CreateConnectionTypeRef(

options = context.GetSettings(options);

// last but not leas we create a type reference that can be put on the field definition
// last but not least we create a type reference that can be put on the field definition
// to tell the type discovery that this field needs this result type.
return CreateConnectionType(
connectionName,
Expand Down
124 changes: 76 additions & 48 deletions src/HotChocolate/Core/src/Types.FSharp/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
".NETStandard,Version=v2.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[8.0.100-beta.23475.2, )",
"resolved": "8.0.100-beta.23475.2",
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
"requested": "[8.0.100, )",
"resolved": "8.0.100",
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down Expand Up @@ -210,6 +210,7 @@
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
"HotChocolate.Fetching": "[0.0.0, )",
"HotChocolate.Types": "[0.0.0, )",
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
"HotChocolate.Validation": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )",
"System.Threading.Channels": "[6.0.0, )"
Expand Down Expand Up @@ -291,6 +292,12 @@
"System.Threading.Tasks.Extensions": "[4.5.4, )"
}
},
"hotchocolate.utilities.dependencyinjection": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )"
}
},
"hotchocolate.validation": {
"type": "Project",
"dependencies": {
Expand All @@ -303,9 +310,9 @@
"net6.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[8.0.100-beta.23475.2, )",
"resolved": "8.0.100-beta.23475.2",
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
"requested": "[8.0.100, )",
"resolved": "8.0.100",
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down Expand Up @@ -444,6 +451,7 @@
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
"HotChocolate.Fetching": "[0.0.0, )",
"HotChocolate.Types": "[0.0.0, )",
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
"HotChocolate.Validation": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )",
"System.Threading.Channels": "[6.0.0, )"
Expand Down Expand Up @@ -517,6 +525,12 @@
"hotchocolate.utilities": {
"type": "Project"
},
"hotchocolate.utilities.dependencyinjection": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )"
}
},
"hotchocolate.validation": {
"type": "Project",
"dependencies": {
Expand All @@ -529,9 +543,9 @@
"net7.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[8.0.100-beta.23475.2, )",
"resolved": "8.0.100-beta.23475.2",
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
"requested": "[8.0.100, )",
"resolved": "8.0.100",
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down Expand Up @@ -645,6 +659,7 @@
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
"HotChocolate.Fetching": "[0.0.0, )",
"HotChocolate.Types": "[0.0.0, )",
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
"HotChocolate.Validation": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection": "[7.0.0, )",
"System.Threading.Channels": "[7.0.0, )"
Expand Down Expand Up @@ -718,6 +733,12 @@
"hotchocolate.utilities": {
"type": "Project"
},
"hotchocolate.utilities.dependencyinjection": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "[7.0.0, )"
}
},
"hotchocolate.validation": {
"type": "Project",
"dependencies": {
Expand All @@ -730,9 +751,9 @@
"net8.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[8.0.100-beta.23475.2, )",
"resolved": "8.0.100-beta.23475.2",
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
"requested": "[8.0.100, )",
"resolved": "8.0.100",
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand All @@ -751,35 +772,35 @@
},
"Microsoft.Extensions.DependencyInjection": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "pUD/Gjd0MTrWPD4/SnKazYQvky2EHEtPyGb3FWZkEPWAfYPFVVw5fMRTkfoBPivpWLuxEw4FNK7GX77xEErUQQ==",
"resolved": "8.0.0",
"contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0-rc.2.23479.6"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "QLTBDvE/E05Xl2UVFXOBFIW0VLn/mMJ8DSbTyK6ODsO3sqDs0fyPqydACTnX/nbGZRrTMeud3XDbUrt24ab1EA=="
"resolved": "8.0.0",
"contentHash": "cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg=="
},
"Microsoft.Extensions.ObjectPool": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23480.2",
"contentHash": "iL9VcNK4dbMOLqAHInwcmVxzr+5sXp70m5Tt1uyIkc5SfJUTuFN6VaxrZy3k91oquTtYrkK9DbE5IP18iJUrtw=="
"resolved": "8.0.0",
"contentHash": "4pm+XgxSukskwjzDDfSjG4KNUIOdFF2VaqZZDtTzoyQMOVSnlV6ZM8a9aVu5dg9LVZTB//utzSc8fOi0b0Mb2Q=="
},
"Microsoft.Extensions.Options": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "f2uTnKEleplKK+pVKEg1rOCmM3+cuLpafTpKJzbj9lm8dmj0+dWxb0L6MAt9r1s3OYlIKY5IdkW0TUFKXvRCMg==",
"resolved": "8.0.0",
"contentHash": "JOVOfqpnqlVLUzINQ2fox8evY2SKLYJ3BV8QDe/Jyp21u1T7r45x/R/5QdteURMR5r01GxeJSBBUOCOyaNXA3g==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0-rc.2.23479.6",
"Microsoft.Extensions.Primitives": "8.0.0-rc.2.23479.6"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
"Microsoft.Extensions.Primitives": "8.0.0"
}
},
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "I3fTiDmV+2cCR3VjH+oz49AMgrAqX1cmNiWXmEAituAI7jCLA16uXzvYQTwxhQzov5BTdPVXKGNTxsMb1GpcLQ=="
"resolved": "8.0.0",
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g=="
},
"Microsoft.SourceLink.Common": {
"type": "Transitive",
Expand All @@ -788,8 +809,8 @@
},
"System.Collections.Immutable": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "+iYjFMCIQMT7FCkZgiYY4Xk9fYCmmiPtCLNn3qqMTJ7Jeqa6SfYdFKsAk4XHTPK81Ov0LsFbKKSMDGFggTc+ZA=="
"resolved": "8.0.0",
"contentHash": "AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg=="
},
"System.ComponentModel.Annotations": {
"type": "Transitive",
Expand All @@ -798,26 +819,26 @@
},
"System.Diagnostics.DiagnosticSource": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "D1Fi5wRyRVwriEdlSniYlo2kW8SCGaSCM/alsY8R7eXcW+xCPRB7gohE45X00EiNkhdUrJ3yNfltV8lLK0HoWQ=="
"resolved": "8.0.0",
"contentHash": "c9xLpVz6PL9lp/djOWtk5KPDZq3cSYpmXoJQY524EOtuFl5z9ZtsotpsyrDW40U1DRnQSYvcPKEUV0X//u6gkQ=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "n66ZIJjetmrMq9hJ61Xed2cp9O2zr/VdzhhURjkLDEFOZ38/VpOWnvM3CWCXA18NbM7x0tdKZYex9rj0NimpPA=="
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"System.Text.Json": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "SXMjrmm/e0Om+731AEUgm+81dC+i9mV54nKJGOq9+zTYpzujMCmSQSMS1sgQb0gmiiAfTfRC5WgD3l92cfAP+g==",
"resolved": "8.0.0",
"contentHash": "OdrZO2WjkiEG6ajEFRABTRCi/wuXQPxeV6g8xvUJqdxMvvuCCEk86zPla8UiIQJz3durtUEbNyY/3lIhS0yZvQ==",
"dependencies": {
"System.Text.Encodings.Web": "8.0.0-rc.2.23479.6"
"System.Text.Encodings.Web": "8.0.0"
}
},
"System.Threading.Channels": {
"type": "Transitive",
"resolved": "8.0.0-rc.2.23479.6",
"contentHash": "z8/q0WPKxQsxuzywRbY1oCb2ZO4qgRbE0nYwXjwrIJ7y10796vJl9P2++MF4JcBcKXfNLgw0JSQslMTxXB+C/A=="
"resolved": "8.0.0",
"contentHash": "CMaFr7v+57RW7uZfZkPExsPB6ljwzhjACWW1gfU35Y56rk72B/Wu+sTqxVmGSk4SFUlPc3cjeKND0zktziyjBA=="
},
"System.Threading.Tasks.Extensions": {
"type": "Transitive",
Expand All @@ -827,16 +848,16 @@
"greendonut": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.ObjectPool": "[8.0.0-rc.2.23480.2, )",
"System.Diagnostics.DiagnosticSource": "[8.0.0-rc.2.23479.6, )",
"Microsoft.Extensions.ObjectPool": "[8.0.0, )",
"System.Diagnostics.DiagnosticSource": "[8.0.0, )",
"System.Threading.Tasks.Extensions": "[4.5.0, )"
}
},
"hotchocolate.abstractions": {
"type": "Project",
"dependencies": {
"HotChocolate.Language": "[0.0.0, )",
"System.Collections.Immutable": "[8.0.0-rc.2.23479.6, )"
"System.Collections.Immutable": "[8.0.0, )"
}
},
"hotchocolate.execution": {
Expand All @@ -846,16 +867,17 @@
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
"HotChocolate.Fetching": "[0.0.0, )",
"HotChocolate.Types": "[0.0.0, )",
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
"HotChocolate.Validation": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection": "[8.0.0-rc.2.23479.6, )",
"System.Threading.Channels": "[8.0.0-rc.2.23479.6, )"
"Microsoft.Extensions.DependencyInjection": "[8.0.0, )",
"System.Threading.Channels": "[8.0.0, )"
}
},
"hotchocolate.execution.abstractions": {
"type": "Project",
"dependencies": {
"HotChocolate.Abstractions": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0-rc.2.23479.6, )"
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )"
}
},
"hotchocolate.fetching": {
Expand All @@ -877,7 +899,7 @@
"hotchocolate.language.syntaxtree": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.ObjectPool": "[8.0.0-rc.2.23480.2, )"
"Microsoft.Extensions.ObjectPool": "[8.0.0, )"
}
},
"hotchocolate.language.utf8": {
Expand All @@ -904,10 +926,10 @@
"HotChocolate.Abstractions": "[0.0.0, )",
"HotChocolate.Types.Shared": "[0.0.0, )",
"HotChocolate.Utilities": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0-rc.2.23479.6, )",
"Microsoft.Extensions.ObjectPool": "[8.0.0-rc.2.23480.2, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.ObjectPool": "[8.0.0, )",
"System.ComponentModel.Annotations": "[5.0.0, )",
"System.Text.Json": "[8.0.0-rc.2.23479.6, )"
"System.Text.Json": "[8.0.0, )"
}
},
"hotchocolate.types.shared": {
Expand All @@ -919,12 +941,18 @@
"hotchocolate.utilities": {
"type": "Project"
},
"hotchocolate.utilities.dependencyinjection": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "[8.0.0, )"
}
},
"hotchocolate.validation": {
"type": "Project",
"dependencies": {
"HotChocolate.Types": "[0.0.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0-rc.2.23479.6, )",
"Microsoft.Extensions.Options": "[8.0.0-rc.2.23479.6, )"
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Options": "[8.0.0, )"
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1009,5 +1009,7 @@ Type: `{0}`</value>
<data name="SchemaException_ErrorSummaryText" xml:space="preserve">
<value>For more details look at the `Errors` property.</value>
</data>

<data name="ThrowHelper_PooledServicesNotAllowed" xml:space="preserve">
<value>The keyed service `{0}` cannot be used as a pooled service.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,31 @@ public bool CanHandle(ParameterInfo parameter)
public void ApplyConfiguration(ParameterInfo parameter, ObjectFieldDescriptor descriptor)
{
ServiceExpressionHelper.TryGetServiceKind(parameter, out var kind);

#if NET8_0_OR_GREATER
if (ServiceExpressionHelper.TryGetServiceKey(parameter, out var key))
{
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, kind, key);
}
else
{
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, kind);
}
#else
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, kind);
#endif
}

public Expression Build(ParameterExpressionBuilderContext context)
{
ServiceExpressionHelper.TryGetServiceKind(context.Parameter, out var kind);

#if NET8_0_OR_GREATER
return ServiceExpressionHelper.TryGetServiceKey(context.Parameter, out var key)
? ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, kind, key)
: ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, kind);
#else
return ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, kind);
#endif
}
}
Loading
Loading