diff --git a/README.md b/README.md index 200ab37..9d2dd2c 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,8 @@ Currently, exceptions thrown by request handlers are not serialized, and no type ## Contributing All forms of contribution are welcome! Here is a list of some much needed features. -- [ ] Request cancellation with `CancellationToken` + +- [x] Request cancellation with `CancellationToken` - [ ] Dynamic buffers for requests in `MediatorServerBase` - [ ] `IPublisher` implementation - [ ] Routing of `INotification` to `INotificationHandler` designated for IPC via DI container. diff --git a/src/Mediator/IPCMediator.PublicStatics.cs b/src/Mediator/IPCMediator.PublicStatics.cs index 8ea3fa9..3e0014b 100644 --- a/src/Mediator/IPCMediator.PublicStatics.cs +++ b/src/Mediator/IPCMediator.PublicStatics.cs @@ -10,6 +10,7 @@ namespace MediatR { public abstract partial class IPCMediator { + private static readonly Type NotificationType = typeof(INotification); private static readonly Type RequestType = typeof(IRequest<>); private static readonly Type UnitType = typeof(Unit); @@ -29,9 +30,9 @@ public static IPCBuilder> RegisterAssemblyTypes(Asse { var types = assembly.ExportedTypes; var requests = assembly.ExportedTypes - .Where(t => t + .Where(t => t .GetInterfaces() - .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == RequestType) + .Any(i => IsRequest(i) || IsNotification(i)) ); var builder = new IPCBuilder>(requests); @@ -40,6 +41,13 @@ public static IPCBuilder> RegisterAssemblyTypes(Asse return builder; } + private static bool IsRequest(Type i) + => i.IsGenericType && i.GetGenericTypeDefinition() == RequestType; + + + private static bool IsNotification(Type i) + => i == NotificationType; + /// /// Registers a request to be handled by the IPC mediator. /// diff --git a/src/Mediators/MediatorClient.cs b/src/Mediators/MediatorClient.cs index 0f6a9a4..20d1479 100644 --- a/src/Mediators/MediatorClient.cs +++ b/src/Mediators/MediatorClient.cs @@ -70,7 +70,7 @@ private object DeserializeResponse(Message response, Type contentType) if (response.IsNullResponse) { - return default!; + return default(Unit); } return DeserializeContent(response , contentType);