{"id":34715923,"url":"https://github.com/russkyc/messaging","last_synced_at":"2026-01-20T17:00:06.627Z","repository":{"id":325744256,"uuid":"1102221409","full_name":"russkyc/messaging","owner":"russkyc","description":"The lightweight, high-performance messaging library extracted from the CommunityToolkit.Mvvm project","archived":false,"fork":false,"pushed_at":"2025-11-23T05:22:18.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-23T06:16:46.416Z","etag":null,"topics":["community-toolkit","events","messaging","mvvm","pubsub","subscription"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Russkyc.Messaging","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/russkyc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-23T03:27:23.000Z","updated_at":"2025-11-23T05:32:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/russkyc/messaging","commit_stats":null,"previous_names":["russkyc/messaging"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/russkyc/messaging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russkyc%2Fmessaging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russkyc%2Fmessaging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russkyc%2Fmessaging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russkyc%2Fmessaging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/russkyc","download_url":"https://codeload.github.com/russkyc/messaging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russkyc%2Fmessaging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["community-toolkit","events","messaging","mvvm","pubsub","subscription"],"created_at":"2025-12-25T00:56:36.627Z","updated_at":"2026-01-20T17:00:06.614Z","avatar_url":"https://github.com/russkyc.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\u003ch2 align=\"center\"\u003eRusskyc.Messaging - Independently packaged Messaging subset from CommunityToolkit.MVVM\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/-.NET%208.0-blueviolet?color=1f72de\u0026label=NET\" alt=\"\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/-.NET%209.0-blueviolet?color=1f72de\u0026label=NET\" alt=\"\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/-.NET%2010.0-blueviolet?color=1f72de\u0026label=NET\" alt=\"\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/russkyc/messaging\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/russkyc/messaging\"\u003e\n    \u003cimg src=\"https://img.shields.io/nuget/v/Russkyc.Messaging?color=1f72de\" alt=\"Nuget\"\u003e\n    \u003cimg src=\"https://img.shields.io/nuget/dt/Russkyc.Messaging\"\u003e\n\u003c/p\u003e\n\nThe lightweight, high-performance messaging library extracted from the [CommunityToolkit.Mvvm](https://github.com/CommunityToolkit/dotnet) project. This library provides a decoupled way for different parts of your application to communicate through messages, supporting both strong and weak reference implementations.\n\n## Features\n\n- **Decoupled Communication**: Send messages between different components without tight coupling\n- **Multiple Messenger Types**: Choose between `StrongReferenceMessenger` and `WeakReferenceMessenger`\n- **Channel Support**: Use tokens to create separate communication channels\n- **Thread-Safe**: All operations are thread-safe\n- **High Performance**: Optimized for minimal overhead\n- **Observable Support**: Integration with reactive programming patterns\n- **Request/Response Patterns**: Built-in support for request messages and responses\n\n## Installation\n\nInstall via NuGet Package Manager:\n\n```bash\ndotnet add package Russkyc.Messaging\n```\n\nOr via Package Manager Console:\n\n```powershell\nInstall-Package Russkyc.Messaging\n```\n\n## Quick Start\n\n### Basic Usage\n\n```csharp\nusing Russkyc.Messaging;\n\n// In your main method or somewhere else\nvar handler = new MessageHandler();\n\n// Send a message\nWeakReferenceMessenger.Default.Send(new UserLoggedInMessage(\"john_doe\"));\n\n// Define a message\npublic record UserLoggedInMessage(string Username);\n\n// Create a recipient\npublic class MessageHandler\n{\n    public MessageHandler()\n    {\n        // Register to receive messages\n        WeakReferenceMessenger.Default.Register\u003cUserLoggedInMessage\u003e(this, OnUserLoggedIn);\n    }\n\n    private void OnUserLoggedIn(object recipient, UserLoggedInMessage message)\n    {\n        Console.WriteLine($\"User {message.Username} logged in!\");\n    }\n}\n```\n\n### Using Custom Messengers\n\n```csharp\n// Create a custom messenger instance\nvar messenger = new WeakReferenceMessenger();\n\n// Create a handler instance\nvar handler = new MessageHandler();\n\n// Register a recipient\nmessenger.Register\u003cUserLoggedInMessage\u003e(handler, (recipient, message) =\u003e\n{\n    Console.WriteLine($\"Custom messenger: User {message.Username} logged in!\");\n});\n\n// Send a message\nmessenger.Send(new UserLoggedInMessage(\"jane_doe\"));\n```\n\n### Using Channels (Tokens)\n\n```csharp\n// Create a handler for admin messages\nvar adminHandler = new object();\n\n// Register on a specific channel\nWeakReferenceMessenger.Default.Register\u003cUserLoggedInMessage, AdminChannel\u003e(\n    adminHandler, \n    new AdminChannel(), \n    (recipient, message) =\u003e Console.WriteLine($\"Admin: {message.Username} logged in!\"));\n\n// Send to a specific channel\nWeakReferenceMessenger.Default.Send(\n    new UserLoggedInMessage(\"admin\"), \n    new AdminChannel());\n\n// Define a token for a specific channel\npublic class AdminChannel { }\n\n```\n\n## Request/Response Patterns\n\nThe library supports both synchronous and asynchronous request/response messaging patterns using `RequestMessage\u003cT\u003e` and `AsyncRequestMessage\u003cT\u003e` respectively.\n\n### Synchronous Requests\n\nSynchronous requests allow you to send a message and immediately receive a response:\n\n```csharp\nusing Russkyc.Messaging;\n\n// Create a handler for requests\nvar requestHandler = new object();\n\n// Handle the request\nWeakReferenceMessenger.Default.Register\u003cGetUserDataRequest\u003e(requestHandler, (recipient, message) =\u003e\n{\n    // Simulate data retrieval\n    var userData = new UserData { Name = \"John Doe\", Email = \"john@example.com\" };\n    message.Reply(userData);\n});\n\n// Send a request and get response\nvar request = new GetUserDataRequest { UserId = \"123\" };\nvar response = WeakReferenceMessenger.Default.Send(request);\nConsole.WriteLine($\"User: {response.Name}, Email: {response.Email}\");\n\n// Define a request message\npublic class GetUserDataRequest : RequestMessage\u003cUserData\u003e\n{\n    public string UserId { get; init; }\n}\n\n// Define response data\npublic class UserData\n{\n    public string Name { get; set; }\n    public string Email { get; set; }\n}\n```\n\n### Asynchronous Requests\n\nAsynchronous requests are useful when the response requires async operations like I/O:\n\n```csharp\nusing Russkyc.Messaging;\n\n// Create a handler for async requests\nvar asyncHandler = new object();\n\n// Handle async request\nWeakReferenceMessenger.Default.Register\u003cAsyncDataRequest\u003e(asyncHandler, async (recipient, message) =\u003e\n{\n    // Simulate async data retrieval\n    await Task.Delay(100); // Simulate async work\n    var data = \"Async data result\";\n    message.Reply(data);\n});\n\n// Send async request\nvar request = new AsyncDataRequest();\nvar response = await WeakReferenceMessenger.Default.Send(request);\nConsole.WriteLine($\"Data: {response}\");\n\n// Define an async request message\npublic class AsyncDataRequest : AsyncRequestMessage\u003cstring\u003e { }\n```\n\n## Messenger Types\n\n### WeakReferenceMessenger (Recommended)\n\n- Uses weak references to track recipients\n- Recipients are automatically unregistered when garbage collected\n- Prevents memory leaks\n- Slightly higher overhead due to weak reference management\n\n```csharp\nvar messenger = new WeakReferenceMessenger();\n```\n\n### StrongReferenceMessenger\n\n- Uses strong references to track recipients\n- Recipients must be manually unregistered\n- Better performance\n- Risk of memory leaks if not properly managed\n\n```csharp\nvar messenger = new StrongReferenceMessenger();\n```\n\n## API Reference\n\n### Core Interfaces\n\n- `IMessenger`: Main interface for messaging functionality\n\n### Message Types\n\nThe library provides several built-in message types for different communication patterns:\n\n- **RequestMessage\u003cT\u003e**: Synchronous request/response messaging. Handlers call `message.Reply(T response)` to send a response.\n- **AsyncRequestMessage\u003cT\u003e**: Asynchronous request/response messaging. Handlers call `message.Reply(T response)` after async operations.\n- **CollectionRequestMessage\u003cT\u003e**: Request for collections of data. Handlers call `message.Reply(IEnumerable\u003cT\u003e response)`.\n- **AsyncCollectionRequestMessage\u003cT\u003e**: Asynchronous request for collections. Handlers call `message.Reply(IEnumerable\u003cT\u003e response)`.\n- **PropertyChangedMessage\u003cT\u003e**: Notifies about property changes. Contains `PropertyName` and `OldValue`/`NewValue`.\n- **ValueChangedMessage\u003cT\u003e**: Notifies about value changes. Contains `OldValue` and `NewValue`.\n\n### Key Methods\n\n- `Register\u003cTMessage\u003e(recipient, handler)`: Register a message handler\n- `Unregister\u003cTMessage\u003e(recipient)`: Unregister from a message type\n- `Send\u003cTMessage\u003e(message)`: Send a message to all registered recipients\n- `IsRegistered\u003cTMessage\u003e(recipient)`: Check if a recipient is registered\n\n### Extension Methods\n\nThe `IMessengerExtensions` class provides convenient extension methods for common operations.\n\n## Performance Considerations\n\n- Use `WeakReferenceMessenger` for long-lived applications to prevent memory leaks\n- Prefer `StrongReferenceMessenger` for short-lived scenarios where performance is critical\n- Use channels (tokens) to reduce message broadcasting overhead\n- Consider the frequency of message sending in performance-critical paths\n\n## Building from Source\n\n1. Clone the repository\n2. Ensure you have .NET 8.0 SDK installed\n3. Run `dotnet build` in the project directory\n\n## Contributing\n\nContributions are welcome! Please feel free to submit issues and pull requests.\n\n## Credits\n\nThis library is a subset of the messaging functionality from [CommunityToolkit.Mvvm](https://github.com/CommunityToolkit/dotnet), extracted and independently packaged.\n\nThe original code is licensed under the MIT License by the .NET Foundation and Contributors.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusskyc%2Fmessaging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusskyc%2Fmessaging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusskyc%2Fmessaging/lists"}