Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/trympet/MediatR.IPC
Browse files Browse the repository at this point in the history
  • Loading branch information
trympet committed May 4, 2021
2 parents f252293 + 4010a00 commit e4ec202
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
12 changes: 10 additions & 2 deletions src/Mediator/IPCMediator.PublicStatics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -29,9 +30,9 @@ public static IPCBuilder<Assembly, IEnumerable<Type>> RegisterAssemblyTypes(Asse
{
var types = assembly.ExportedTypes;
var requests = assembly.ExportedTypes
.Where(t => t
.Where<Type>(t => t
.GetInterfaces()
.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == RequestType)
.Any(i => IsRequest(i) || IsNotification(i))
);

var builder = new IPCBuilder<Assembly, IEnumerable<Type>>(requests);
Expand All @@ -40,6 +41,13 @@ public static IPCBuilder<Assembly, IEnumerable<Type>> RegisterAssemblyTypes(Asse
return builder;
}

private static bool IsRequest(Type i)
=> i.IsGenericType && i.GetGenericTypeDefinition() == RequestType;


private static bool IsNotification(Type i)
=> i == NotificationType;

/// <summary>
/// Registers a request to be handled by the IPC mediator.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Mediators/MediatorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private object DeserializeResponse(Message response, Type contentType)

if (response.IsNullResponse)
{
return default!;
return default(Unit);
}

return DeserializeContent(response , contentType);
Expand Down

0 comments on commit e4ec202

Please sign in to comment.