diff --git a/src/HotChocolate/Utilities/src/Utilities/ServiceFactory.cs b/src/HotChocolate/Utilities/src/Utilities/ServiceFactory.cs index f4b3ac8af93..62894e752b7 100644 --- a/src/HotChocolate/Utilities/src/Utilities/ServiceFactory.cs +++ b/src/HotChocolate/Utilities/src/Utilities/ServiceFactory.cs @@ -12,6 +12,11 @@ public class ServiceFactory : IServiceProvider public object? CreateInstance(Type type) { + if (type is null) + { + throw new ArgumentNullException(nameof(type)); + } + try { return ActivatorHelper.CompileFactory(type).Invoke(Services ?? _empty); diff --git a/src/HotChocolate/Utilities/test/Utilities.Tests/ActivatorHelperTests.cs b/src/HotChocolate/Utilities/test/Utilities.Tests/ActivatorHelperTests.cs index 44a85d70500..8914a309542 100644 --- a/src/HotChocolate/Utilities/test/Utilities.Tests/ActivatorHelperTests.cs +++ b/src/HotChocolate/Utilities/test/Utilities.Tests/ActivatorHelperTests.cs @@ -57,19 +57,6 @@ public void CreateInstanceFactory_From_AbstactClass() .Message.MatchSnapshot(); } - [Fact] - public void CreateInstanceFactory_From_Class_With_Multiple_Constructors() - { - // arrange - // act - Action action = () => ActivatorHelper - .CompileFactory(typeof(Foo).GetTypeInfo()); - - // assert - Assert.Throws(action) - .Message.MatchSnapshot(); - } - public interface IFoo { diff --git a/website/src/blog/2020-07-16-version-11/2020-07-16-version-11.md b/website/src/blog/2020-07-16-version-11/2020-07-16-version-11.md index 3ee094324be..2b4b09651c1 100644 --- a/website/src/blog/2020-07-16-version-11/2020-07-16-version-11.md +++ b/website/src/blog/2020-07-16-version-11/2020-07-16-version-11.md @@ -119,3 +119,47 @@ public void ConfigureServices(IServiceCollection services) Again, I can have in-memory subscriptions on one schema and Redis subscriptions on the other. +Next we need to define our `Mutation` type in order to trigger subscriptions whenever something happens on our server. + +```csharp +public class Mutation +{ + public string SendMessage( + string userId + string message, + [Service] ITopicEventSender eventSender) + { + eventSender.SendAsync(userId, message); + return message; + } +} +``` + +In our example we have a mutation that can send a text message to a user represented by the user API. In order to send a message to our subscription bus we are using the userId argument as a topic and the message as a payload and use the injected `ITopicEventSender` to send the message. + +In our subscription type we do not need to handle the receive process or anything. We just specify what the topic is and what the message is and everything will be automatically injected. + +```csharp +public class Subscription +{ + [Subscribe] + public string OnMessage( + [Topic] string userId, + [EventMessage] string message) => + message; +} +``` + +The userId in this instance is an argument that is provided from the outside, whereas the message is a parameter where the subscription bus injects the sent message into our resolver. + +```graphql +subscription onMessage { + onMessage(userId: "123"); +} +``` + +There are a lot more variants with the new subscriptions but I will cover that in a later blog post that only looks at subscriptions and what we can do with them. + +## Extensibility + +We put a big emphasis \ No newline at end of file