-
-
Save dcomartin/a86eabd6a9c033129ec6ae85f6c10ace to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BlazorClient; | |
using Microsoft.AspNetCore.SignalR; | |
namespace UndoExample; | |
public record Tweet(Guid TweetId, string Message) : ICommand; | |
public record Tweeted(Guid TweetId, string Message) : IEvent; | |
public class TweetHandler : IHandleMessages<Tweet> | |
{ | |
private readonly ILogger<TweetHandler> _logger; | |
public TweetHandler(ILogger<TweetHandler> logger) | |
{ | |
_logger = logger; | |
} | |
public async Task Handle(Tweet message, IMessageHandlerContext context) | |
{ | |
_logger.LogInformation($"Tweeted: {message.Message}"); | |
// Do something here like persisting the tweet to the DB. | |
await context.Publish(new Tweeted(message.TweetId, message.Message)); | |
} | |
} | |
public class TweetedSignalRHandler : IHandleMessages<Tweeted> | |
{ | |
private readonly IHubContext<TweetHub> _hubContext; | |
public TweetedSignalRHandler(IHubContext<TweetHub> hubContext) | |
{ | |
_hubContext = hubContext; | |
} | |
public async Task Handle(Tweeted message, IMessageHandlerContext context) | |
{ | |
await _hubContext.Clients.All.SendAsync("tweeted", message.TweetId, message.Message, context.CancellationToken); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment