using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
public class NotificationMessage
public string Content { get; }
public NotificationMessage(string content) => Content = content;
public class GetUserRequest : RequestMessage<User> { }
public string Name { get; set; }
public class UserViewModel : ObservableRecipient, IRecipient<NotificationMessage>, IRecipient<GetUserRequest>
public void Receive(NotificationMessage message)
Console.WriteLine($"Notification: {message.Content}");
public void Receive(GetUserRequest request)
request.Reply(new User { Name = "John Doe" });
static void Main(string[] args)
var viewModel = new UserViewModel();
var request = new GetUserRequest();
WeakReferenceMessenger.Default.Send(request);
var user = request.Response;
Console.WriteLine($"User: {user.Name}");