MediatR - 1.0

Extension ID

com.castsoftware.dotnet.mediatr

What’s new?

See MediatR for .NET - 1.0 - Release Notes for more information.

Description

This extension provides support for MediatR for .NET APIs which are responsible for publishing and receiving messages across messaging queues.

In what situation should you install this extension?

If your C# application utilizes MediatR for messaging and you want to view a model that shows the message publisher and receiver objects with their corresponding links, then you should install this extension.

Technology support

The following libraries are supported by this extension:

Language Library name Namespace Version Supported
.NET MediatR MediatR 0.1.0 to 12.3.0

Compatibility 

This extension is compatible with:

CAST Imaging Core release Supported
8.3.x

Dependencies

The MediatR extension is dependent on following extensions:

  • CAST AIP Internal extension (com.castsoftware.internal.platform)

Download and installation instructions

The extension will not be automatically downloaded and installed in CAST Console. If you need to use it, you should manually install the extension using the Application - Extensions interface:

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the below objects and links created.

Objects

Icon Description Comment
MediatR DotNet Publisher an object is created for each message published and message type is resolved
MediatR DotNet Receiver an object is created for each resolved Message Handler
MediatR Unknown DotNet Publisher an object is created for each message published and message type is not resolved in a method call
MediatR Unknown DotNet Receiver an object is created for each unresolved message handler
Link Type Source and Destination Link Supported APIs
callLink Link between the caller C# method and the DotNet MediatR Publisher object
MediatR Publisher APIs
MediatR.ISender.Send
MediatR.Mediator.Send
MediatR.INotificationPublisher.Publish
MediatR.IPublisher.Publish
MediatR.Mediator.Publish
MediatR.IMediator.Publish
MediatR.IMediator.Send
MediatR.NotificationPublishers.ForeachAwaitPublisher.Publish
MediatR.NotificationPublishers.TaskWhenAllPublisher.Publish
callLink Link between the DotNet MediatR Receiver object and the caller C# method
MediatR Receiver APIs
MediatR.IRequestHandler
MediatR.INotification
MediatR.Wrappers.RequestHandlerBase
MediatR.Wrappers.RequestHandlerWrapper
MediatR.Wrappers.NotificationHandlerWrapper
MediatR.INotificationHandler
MediatR.IPipelineBehavior<TRequest, TResponse>
MediatR.IPipelineBehavior
MediatR.Wrappers.RequestHandlerWrapper
MediatR.Wrappers.StreamRequestHandlerBase
MediatR.Wrappers.StreamRequestHandlerWrapper
MediatR.INotificationHandler`1
MediatR.IPipelineBehavior`2
MediatR.IRequestHandler`1
MediatR.IRequestHandler`2
MediatR.IStreamPipelineBehavior`2
MediatR.IStreamRequestHandler`2
MediatR.NotificationHandler`1
MediatR.Pipeline.IRequestExceptionHandler`3
MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2
MediatR.Pipeline.RequestPostProcessorBehavior`2
MediatR.Pipeline.RequestPreProcessorBehavior`2
MediatR.Wrappers.RequestHandlerWrapperImpl`1
MediatR.Wrappers.NotificationHandlerWrapperImpl`1
MediatR.Wrappers.RequestHandlerWrapper`1
MediatR.Wrappers.RequestHandlerWrapperImpl`2

Code Examples

Publisher

Publish

class Program
    {
        static async Task Main(string[] args)
        {
            // Create a MediatR instance
            var mediator = new Mediator();

            // Add the handlers directly to the Mediator
            mediator.AddMediator(new MySecondMessageHandler());

            // Publish a message
            await mediator.Publish(new MyMessage { Message = "Hello, World!" });

        }
    }

Send

class Program
    {
        static async Task Main(string[] args)
        {
            // Create a MediatR instance
            var mediator = new Mediator();

            // Add the handlers directly to the Mediator
            mediator.AddMediator(new MyMessageHandler());

            // Send a message
            await mediator.Send(new MyMessage { Message = "Hello, World!" });

        }
    }

Unknown

public Task Should_raise_execption_on_null_request() => Should.ThrowAsync<ArgumentNullException>(async () => await _mediator.Send(default!));

Receiver

IRequestHandler.Handle


// Define a handler class
public class MyMessageHandler : IRequestHandler<MyMessage>
{
    public Task Handle(MyMessage request)
    {
        Console.WriteLine($"Received message: {request.Message}");
        return Task.CompletedTask;
    }
}