From b58631905c1f03f99c55edccaae4770cf3ccead8 Mon Sep 17 00:00:00 2001 From: Duke <40759437+dukesteen@users.noreply.github.com> Date: Thu, 31 Mar 2022 17:57:35 +0200 Subject: [PATCH] Fix review points --- docs/guides/other_libs/mediatr.md | 10 +++++----- .../samples/MediatrCreatingMessageNotification.cs | 2 +- .../other_libs/samples/MediatrDiscordEventListener.cs | 7 +++++-- .../samples/MediatrMessageReceivedHandler.cs | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/guides/other_libs/mediatr.md b/docs/guides/other_libs/mediatr.md index 3452ed7bb..832628738 100644 --- a/docs/guides/other_libs/mediatr.md +++ b/docs/guides/other_libs/mediatr.md @@ -11,7 +11,7 @@ title: MediatR ## Downloading the required packages -You can install the following packages through your IDE or go to the nuget link to grab the dotnet cli command. +You can install the following packages through your IDE or go to the NuGet link to grab the dotnet cli command. |Name|Link| |--|--| @@ -32,7 +32,7 @@ The way MediatR publishes events throughout your applications is through notific ## Creating the notification publisher / event listener -For MediatR to actually publish the events we need a way to listen for them. We will create a class to listen for discord events like so. +For MediatR to actually publish the events we need a way to listen for them. We will create a class to listen for discord events like so: [!code-csharp[Creating an event listener](samples/MediatrDiscordEventListener.cs)] @@ -46,7 +46,7 @@ To start the listener we have to call the `StartAsync()` method on our `DiscordE ## Creating your notification handler -MediatR publishes notifications to all of your notification handlers that are listening for a specific notification. We will create a handler for our newly created `MessageReceivedNotification` like this +MediatR publishes notifications to all of your notification handlers that are listening for a specific notification. We will create a handler for our newly created `MessageReceivedNotification` like this: [!code-csharp[Creating an event listener](samples/MediatrMessageReceivedHandler.cs)] @@ -63,8 +63,8 @@ To test if we have successfully implemented MediatR, we can start up the bot and ## Adding more event types -To add more event types you can follow these steps +To add more event types you can follow these steps: 1. Create a new notification class for the event. it should contain all of the parameters that the event would send. (Ex: the `MessageReceived` event takes one `SocketMessage` as an argument. The notification class should also map this argument) -2. Register the event in your `DiscordEventListener` class +2. Register the event in your `DiscordEventListener` class. 3. Create a notification handler for your new notification. diff --git a/docs/guides/other_libs/samples/MediatrCreatingMessageNotification.cs b/docs/guides/other_libs/samples/MediatrCreatingMessageNotification.cs index 7e3c7c7f5..449c96eb4 100644 --- a/docs/guides/other_libs/samples/MediatrCreatingMessageNotification.cs +++ b/docs/guides/other_libs/samples/MediatrCreatingMessageNotification.cs @@ -3,7 +3,7 @@ using Discord.WebSocket; using MediatR; -namespace Viscoin.Bot.Infrastructure.Messages; +namespace MediatRSample.Notifications; public class MessageReceivedNotification : INotification { diff --git a/docs/guides/other_libs/samples/MediatrDiscordEventListener.cs b/docs/guides/other_libs/samples/MediatrDiscordEventListener.cs index f5c67b534..8f52976cd 100644 --- a/docs/guides/other_libs/samples/MediatrDiscordEventListener.cs +++ b/docs/guides/other_libs/samples/MediatrDiscordEventListener.cs @@ -4,6 +4,9 @@ using Discord.WebSocket; using MediatR; using MediatRSample.Notifications; using Microsoft.Extensions.DependencyInjection; +using System.Threading; +using System.Threading.Tasks; + namespace MediatRSample; @@ -30,11 +33,11 @@ public class DiscordEventListener } } - public Task StartAsync() + public async Task StartAsync() { _client.MessageReceived += OnMessageReceivedAsync; - return Task.CompletedTask; + await Task.CompletedTask; } private Task OnMessageReceivedAsync(SocketMessage arg) diff --git a/docs/guides/other_libs/samples/MediatrMessageReceivedHandler.cs b/docs/guides/other_libs/samples/MediatrMessageReceivedHandler.cs index a6baa03a3..1ab2491e2 100644 --- a/docs/guides/other_libs/samples/MediatrMessageReceivedHandler.cs +++ b/docs/guides/other_libs/samples/MediatrMessageReceivedHandler.cs @@ -1,5 +1,6 @@ // MessageReceivedHandler.cs +using System; using MediatR; using MediatRSample.Notifications;