Skip to content

Commit 0a2e0fc

Browse files
authored
Added Support for Keyed Service Attribute (#6810)
1 parent e4cb074 commit 0a2e0fc

File tree

16 files changed

+536
-4850
lines changed

16 files changed

+536
-4850
lines changed

src/HotChocolate/Core/src/Abstractions/ServiceAttribute.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace HotChocolate;
66
/// Marks a resolver parameter as a service that shall be injected by the execution engine.
77
/// </summary>
88
[AttributeUsage(AttributeTargets.Parameter)]
9-
public sealed class ServiceAttribute : Attribute
9+
public class ServiceAttribute : Attribute
1010
{
1111
/// <summary>
1212
/// Marks a resolver parameter as a service that shall be injected by the execution engine.
@@ -19,6 +19,28 @@ public ServiceAttribute(ServiceKind kind = ServiceKind.Default)
1919
Kind = kind;
2020
}
2121

22+
#if NET8_0_OR_GREATER
23+
/// <summary>
24+
/// Marks a resolver parameter as a service that shall be injected by the execution engine.
25+
/// </summary>
26+
/// <param name="key">
27+
/// A key that shall be used to resolve the service.
28+
/// </param>
29+
/// <param name="kind">
30+
/// The scope of the service.
31+
/// </param>
32+
public ServiceAttribute(string key, ServiceKind kind = ServiceKind.Default)
33+
{
34+
Key = key;
35+
Kind = kind;
36+
}
37+
38+
/// <summary>
39+
/// Gets the key that shall be used to resolve the service.
40+
/// </summary>
41+
public string? Key { get; }
42+
#endif
43+
2244
/// <summary>
2345
/// Gets the service kind which specifies the way the service
2446
/// shall be injected and handled by the execution engine.

src/HotChocolate/Core/src/Types.CursorPagination/Extensions/PagingObjectFieldDescriptorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ private static TypeReference CreateConnectionTypeRef(
342342

343343
options = context.GetSettings(options);
344344

345-
// last but not leas we create a type reference that can be put on the field definition
345+
// last but not least we create a type reference that can be put on the field definition
346346
// to tell the type discovery that this field needs this result type.
347347
return CreateConnectionType(
348348
connectionName,

src/HotChocolate/Core/src/Types.FSharp/packages.lock.json

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
".NETStandard,Version=v2.0": {
55
"FSharp.Core": {
66
"type": "Direct",
7-
"requested": "[8.0.100-beta.23475.2, )",
8-
"resolved": "8.0.100-beta.23475.2",
9-
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
7+
"requested": "[8.0.100, )",
8+
"resolved": "8.0.100",
9+
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
1010
},
1111
"Microsoft.SourceLink.GitHub": {
1212
"type": "Direct",
@@ -210,6 +210,7 @@
210210
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
211211
"HotChocolate.Fetching": "[0.0.0, )",
212212
"HotChocolate.Types": "[0.0.0, )",
213+
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
213214
"HotChocolate.Validation": "[0.0.0, )",
214215
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )",
215216
"System.Threading.Channels": "[6.0.0, )"
@@ -291,6 +292,12 @@
291292
"System.Threading.Tasks.Extensions": "[4.5.4, )"
292293
}
293294
},
295+
"hotchocolate.utilities.dependencyinjection": {
296+
"type": "Project",
297+
"dependencies": {
298+
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )"
299+
}
300+
},
294301
"hotchocolate.validation": {
295302
"type": "Project",
296303
"dependencies": {
@@ -303,9 +310,9 @@
303310
"net6.0": {
304311
"FSharp.Core": {
305312
"type": "Direct",
306-
"requested": "[8.0.100-beta.23475.2, )",
307-
"resolved": "8.0.100-beta.23475.2",
308-
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
313+
"requested": "[8.0.100, )",
314+
"resolved": "8.0.100",
315+
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
309316
},
310317
"Microsoft.SourceLink.GitHub": {
311318
"type": "Direct",
@@ -444,6 +451,7 @@
444451
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
445452
"HotChocolate.Fetching": "[0.0.0, )",
446453
"HotChocolate.Types": "[0.0.0, )",
454+
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
447455
"HotChocolate.Validation": "[0.0.0, )",
448456
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )",
449457
"System.Threading.Channels": "[6.0.0, )"
@@ -517,6 +525,12 @@
517525
"hotchocolate.utilities": {
518526
"type": "Project"
519527
},
528+
"hotchocolate.utilities.dependencyinjection": {
529+
"type": "Project",
530+
"dependencies": {
531+
"Microsoft.Extensions.DependencyInjection": "[6.0.0, )"
532+
}
533+
},
520534
"hotchocolate.validation": {
521535
"type": "Project",
522536
"dependencies": {
@@ -529,9 +543,9 @@
529543
"net7.0": {
530544
"FSharp.Core": {
531545
"type": "Direct",
532-
"requested": "[8.0.100-beta.23475.2, )",
533-
"resolved": "8.0.100-beta.23475.2",
534-
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
546+
"requested": "[8.0.100, )",
547+
"resolved": "8.0.100",
548+
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
535549
},
536550
"Microsoft.SourceLink.GitHub": {
537551
"type": "Direct",
@@ -645,6 +659,7 @@
645659
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
646660
"HotChocolate.Fetching": "[0.0.0, )",
647661
"HotChocolate.Types": "[0.0.0, )",
662+
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
648663
"HotChocolate.Validation": "[0.0.0, )",
649664
"Microsoft.Extensions.DependencyInjection": "[7.0.0, )",
650665
"System.Threading.Channels": "[7.0.0, )"
@@ -718,6 +733,12 @@
718733
"hotchocolate.utilities": {
719734
"type": "Project"
720735
},
736+
"hotchocolate.utilities.dependencyinjection": {
737+
"type": "Project",
738+
"dependencies": {
739+
"Microsoft.Extensions.DependencyInjection": "[7.0.0, )"
740+
}
741+
},
721742
"hotchocolate.validation": {
722743
"type": "Project",
723744
"dependencies": {
@@ -730,9 +751,9 @@
730751
"net8.0": {
731752
"FSharp.Core": {
732753
"type": "Direct",
733-
"requested": "[8.0.100-beta.23475.2, )",
734-
"resolved": "8.0.100-beta.23475.2",
735-
"contentHash": "EEYKMpieataf/B7mcoHTDPGw8cnREa1AKwyFgHtiGwTOEJlzY7XIRMyOQvN4P9aMFh55ILZN6NKgPQrktcnQNg=="
754+
"requested": "[8.0.100, )",
755+
"resolved": "8.0.100",
756+
"contentHash": "ZOVZ/o+jI3ormTZOa28Wh0tSRoyle1f7lKFcUN61sPiXI7eDZu8eSveFybgTeyIEyW0ujjp31cp7GOglDgsNEg=="
736757
},
737758
"Microsoft.SourceLink.GitHub": {
738759
"type": "Direct",
@@ -751,35 +772,35 @@
751772
},
752773
"Microsoft.Extensions.DependencyInjection": {
753774
"type": "Transitive",
754-
"resolved": "8.0.0-rc.2.23479.6",
755-
"contentHash": "pUD/Gjd0MTrWPD4/SnKazYQvky2EHEtPyGb3FWZkEPWAfYPFVVw5fMRTkfoBPivpWLuxEw4FNK7GX77xEErUQQ==",
775+
"resolved": "8.0.0",
776+
"contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==",
756777
"dependencies": {
757-
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0-rc.2.23479.6"
778+
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
758779
}
759780
},
760781
"Microsoft.Extensions.DependencyInjection.Abstractions": {
761782
"type": "Transitive",
762-
"resolved": "8.0.0-rc.2.23479.6",
763-
"contentHash": "QLTBDvE/E05Xl2UVFXOBFIW0VLn/mMJ8DSbTyK6ODsO3sqDs0fyPqydACTnX/nbGZRrTMeud3XDbUrt24ab1EA=="
783+
"resolved": "8.0.0",
784+
"contentHash": "cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg=="
764785
},
765786
"Microsoft.Extensions.ObjectPool": {
766787
"type": "Transitive",
767-
"resolved": "8.0.0-rc.2.23480.2",
768-
"contentHash": "iL9VcNK4dbMOLqAHInwcmVxzr+5sXp70m5Tt1uyIkc5SfJUTuFN6VaxrZy3k91oquTtYrkK9DbE5IP18iJUrtw=="
788+
"resolved": "8.0.0",
789+
"contentHash": "4pm+XgxSukskwjzDDfSjG4KNUIOdFF2VaqZZDtTzoyQMOVSnlV6ZM8a9aVu5dg9LVZTB//utzSc8fOi0b0Mb2Q=="
769790
},
770791
"Microsoft.Extensions.Options": {
771792
"type": "Transitive",
772-
"resolved": "8.0.0-rc.2.23479.6",
773-
"contentHash": "f2uTnKEleplKK+pVKEg1rOCmM3+cuLpafTpKJzbj9lm8dmj0+dWxb0L6MAt9r1s3OYlIKY5IdkW0TUFKXvRCMg==",
793+
"resolved": "8.0.0",
794+
"contentHash": "JOVOfqpnqlVLUzINQ2fox8evY2SKLYJ3BV8QDe/Jyp21u1T7r45x/R/5QdteURMR5r01GxeJSBBUOCOyaNXA3g==",
774795
"dependencies": {
775-
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0-rc.2.23479.6",
776-
"Microsoft.Extensions.Primitives": "8.0.0-rc.2.23479.6"
796+
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
797+
"Microsoft.Extensions.Primitives": "8.0.0"
777798
}
778799
},
779800
"Microsoft.Extensions.Primitives": {
780801
"type": "Transitive",
781-
"resolved": "8.0.0-rc.2.23479.6",
782-
"contentHash": "I3fTiDmV+2cCR3VjH+oz49AMgrAqX1cmNiWXmEAituAI7jCLA16uXzvYQTwxhQzov5BTdPVXKGNTxsMb1GpcLQ=="
802+
"resolved": "8.0.0",
803+
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g=="
783804
},
784805
"Microsoft.SourceLink.Common": {
785806
"type": "Transitive",
@@ -788,8 +809,8 @@
788809
},
789810
"System.Collections.Immutable": {
790811
"type": "Transitive",
791-
"resolved": "8.0.0-rc.2.23479.6",
792-
"contentHash": "+iYjFMCIQMT7FCkZgiYY4Xk9fYCmmiPtCLNn3qqMTJ7Jeqa6SfYdFKsAk4XHTPK81Ov0LsFbKKSMDGFggTc+ZA=="
812+
"resolved": "8.0.0",
813+
"contentHash": "AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg=="
793814
},
794815
"System.ComponentModel.Annotations": {
795816
"type": "Transitive",
@@ -798,26 +819,26 @@
798819
},
799820
"System.Diagnostics.DiagnosticSource": {
800821
"type": "Transitive",
801-
"resolved": "8.0.0-rc.2.23479.6",
802-
"contentHash": "D1Fi5wRyRVwriEdlSniYlo2kW8SCGaSCM/alsY8R7eXcW+xCPRB7gohE45X00EiNkhdUrJ3yNfltV8lLK0HoWQ=="
822+
"resolved": "8.0.0",
823+
"contentHash": "c9xLpVz6PL9lp/djOWtk5KPDZq3cSYpmXoJQY524EOtuFl5z9ZtsotpsyrDW40U1DRnQSYvcPKEUV0X//u6gkQ=="
803824
},
804825
"System.Text.Encodings.Web": {
805826
"type": "Transitive",
806-
"resolved": "8.0.0-rc.2.23479.6",
807-
"contentHash": "n66ZIJjetmrMq9hJ61Xed2cp9O2zr/VdzhhURjkLDEFOZ38/VpOWnvM3CWCXA18NbM7x0tdKZYex9rj0NimpPA=="
827+
"resolved": "8.0.0",
828+
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
808829
},
809830
"System.Text.Json": {
810831
"type": "Transitive",
811-
"resolved": "8.0.0-rc.2.23479.6",
812-
"contentHash": "SXMjrmm/e0Om+731AEUgm+81dC+i9mV54nKJGOq9+zTYpzujMCmSQSMS1sgQb0gmiiAfTfRC5WgD3l92cfAP+g==",
832+
"resolved": "8.0.0",
833+
"contentHash": "OdrZO2WjkiEG6ajEFRABTRCi/wuXQPxeV6g8xvUJqdxMvvuCCEk86zPla8UiIQJz3durtUEbNyY/3lIhS0yZvQ==",
813834
"dependencies": {
814-
"System.Text.Encodings.Web": "8.0.0-rc.2.23479.6"
835+
"System.Text.Encodings.Web": "8.0.0"
815836
}
816837
},
817838
"System.Threading.Channels": {
818839
"type": "Transitive",
819-
"resolved": "8.0.0-rc.2.23479.6",
820-
"contentHash": "z8/q0WPKxQsxuzywRbY1oCb2ZO4qgRbE0nYwXjwrIJ7y10796vJl9P2++MF4JcBcKXfNLgw0JSQslMTxXB+C/A=="
840+
"resolved": "8.0.0",
841+
"contentHash": "CMaFr7v+57RW7uZfZkPExsPB6ljwzhjACWW1gfU35Y56rk72B/Wu+sTqxVmGSk4SFUlPc3cjeKND0zktziyjBA=="
821842
},
822843
"System.Threading.Tasks.Extensions": {
823844
"type": "Transitive",
@@ -827,16 +848,16 @@
827848
"greendonut": {
828849
"type": "Project",
829850
"dependencies": {
830-
"Microsoft.Extensions.ObjectPool": "[8.0.0-rc.2.23480.2, )",
831-
"System.Diagnostics.DiagnosticSource": "[8.0.0-rc.2.23479.6, )",
851+
"Microsoft.Extensions.ObjectPool": "[8.0.0, )",
852+
"System.Diagnostics.DiagnosticSource": "[8.0.0, )",
832853
"System.Threading.Tasks.Extensions": "[4.5.0, )"
833854
}
834855
},
835856
"hotchocolate.abstractions": {
836857
"type": "Project",
837858
"dependencies": {
838859
"HotChocolate.Language": "[0.0.0, )",
839-
"System.Collections.Immutable": "[8.0.0-rc.2.23479.6, )"
860+
"System.Collections.Immutable": "[8.0.0, )"
840861
}
841862
},
842863
"hotchocolate.execution": {
@@ -846,16 +867,17 @@
846867
"HotChocolate.Execution.Abstractions": "[0.0.0, )",
847868
"HotChocolate.Fetching": "[0.0.0, )",
848869
"HotChocolate.Types": "[0.0.0, )",
870+
"HotChocolate.Utilities.DependencyInjection": "[0.0.0, )",
849871
"HotChocolate.Validation": "[0.0.0, )",
850-
"Microsoft.Extensions.DependencyInjection": "[8.0.0-rc.2.23479.6, )",
851-
"System.Threading.Channels": "[8.0.0-rc.2.23479.6, )"
872+
"Microsoft.Extensions.DependencyInjection": "[8.0.0, )",
873+
"System.Threading.Channels": "[8.0.0, )"
852874
}
853875
},
854876
"hotchocolate.execution.abstractions": {
855877
"type": "Project",
856878
"dependencies": {
857879
"HotChocolate.Abstractions": "[0.0.0, )",
858-
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0-rc.2.23479.6, )"
880+
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )"
859881
}
860882
},
861883
"hotchocolate.fetching": {
@@ -877,7 +899,7 @@
877899
"hotchocolate.language.syntaxtree": {
878900
"type": "Project",
879901
"dependencies": {
880-
"Microsoft.Extensions.ObjectPool": "[8.0.0-rc.2.23480.2, )"
902+
"Microsoft.Extensions.ObjectPool": "[8.0.0, )"
881903
}
882904
},
883905
"hotchocolate.language.utf8": {
@@ -904,10 +926,10 @@
904926
"HotChocolate.Abstractions": "[0.0.0, )",
905927
"HotChocolate.Types.Shared": "[0.0.0, )",
906928
"HotChocolate.Utilities": "[0.0.0, )",
907-
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0-rc.2.23479.6, )",
908-
"Microsoft.Extensions.ObjectPool": "[8.0.0-rc.2.23480.2, )",
929+
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
930+
"Microsoft.Extensions.ObjectPool": "[8.0.0, )",
909931
"System.ComponentModel.Annotations": "[5.0.0, )",
910-
"System.Text.Json": "[8.0.0-rc.2.23479.6, )"
932+
"System.Text.Json": "[8.0.0, )"
911933
}
912934
},
913935
"hotchocolate.types.shared": {
@@ -919,12 +941,18 @@
919941
"hotchocolate.utilities": {
920942
"type": "Project"
921943
},
944+
"hotchocolate.utilities.dependencyinjection": {
945+
"type": "Project",
946+
"dependencies": {
947+
"Microsoft.Extensions.DependencyInjection": "[8.0.0, )"
948+
}
949+
},
922950
"hotchocolate.validation": {
923951
"type": "Project",
924952
"dependencies": {
925953
"HotChocolate.Types": "[0.0.0, )",
926-
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0-rc.2.23479.6, )",
927-
"Microsoft.Extensions.Options": "[8.0.0-rc.2.23479.6, )"
954+
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
955+
"Microsoft.Extensions.Options": "[8.0.0, )"
928956
}
929957
}
930958
}

src/HotChocolate/Core/src/Types/Properties/TypeResources.Designer.cs

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Core/src/Types/Properties/TypeResources.resx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,5 +1009,7 @@ Type: `{0}`</value>
10091009
<data name="SchemaException_ErrorSummaryText" xml:space="preserve">
10101010
<value>For more details look at the `Errors` property.</value>
10111011
</data>
1012-
1012+
<data name="ThrowHelper_PooledServicesNotAllowed" xml:space="preserve">
1013+
<value>The keyed service `{0}` cannot be used as a pooled service.</value>
1014+
</data>
10131015
</root>

src/HotChocolate/Core/src/Types/Resolvers/Expressions/Parameters/ScopedServiceParameterExpressionBuilder.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,31 @@ public bool CanHandle(ParameterInfo parameter)
2424
public void ApplyConfiguration(ParameterInfo parameter, ObjectFieldDescriptor descriptor)
2525
{
2626
ServiceExpressionHelper.TryGetServiceKind(parameter, out var kind);
27+
28+
#if NET8_0_OR_GREATER
29+
if (ServiceExpressionHelper.TryGetServiceKey(parameter, out var key))
30+
{
31+
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, kind, key);
32+
}
33+
else
34+
{
35+
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, kind);
36+
}
37+
#else
2738
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, kind);
39+
#endif
2840
}
2941

3042
public Expression Build(ParameterExpressionBuilderContext context)
3143
{
3244
ServiceExpressionHelper.TryGetServiceKind(context.Parameter, out var kind);
45+
46+
#if NET8_0_OR_GREATER
47+
return ServiceExpressionHelper.TryGetServiceKey(context.Parameter, out var key)
48+
? ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, kind, key)
49+
: ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, kind);
50+
#else
3351
return ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, kind);
52+
#endif
3453
}
3554
}

0 commit comments

Comments
 (0)