{"id":23094960,"url":"https://github.com/aksoftware98/blazor-utilities","last_synced_at":"2025-06-15T17:39:05.915Z","repository":{"id":46497346,"uuid":"410558325","full_name":"aksoftware98/blazor-utilities","owner":"aksoftware98","description":"Messaging is a repository that represents the MessagingCenter service available in Xamarin as a package available for all Blazor developers that allows them to send data between components efficiently","archived":false,"fork":false,"pushed_at":"2021-10-09T08:33:46.000Z","size":2242,"stargazers_count":43,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2023-03-04T10:30:44.995Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/aksoftware98.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}},"created_at":"2021-09-26T13:22:53.000Z","updated_at":"2023-02-19T15:25:24.000Z","dependencies_parsed_at":"2022-08-03T02:45:56.714Z","dependency_job_id":null,"html_url":"https://github.com/aksoftware98/blazor-utilities","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksoftware98%2Fblazor-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksoftware98%2Fblazor-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksoftware98%2Fblazor-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aksoftware98%2Fblazor-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aksoftware98","download_url":"https://codeload.github.com/aksoftware98/blazor-utilities/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230032716,"owners_count":18162493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-12-16T22:18:57.820Z","updated_at":"2024-12-16T22:18:58.444Z","avatar_url":"https://github.com/aksoftware98.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to Messaging Center Blazor Utitlity!\n\n\n\u003cimg src=\"https://github.com/aksoftware98/blazor-utilities/blob/main/Assets/Blazor%20Utitlies.png?raw=true\" alt=\"drawing\" width=\"200\" style=\"width:200px\"/\u003e\n\n### AKSoftware.Blazor.Utilities \n\n#### ⚡ ⚡ 🚀 Send data across your components fluently with the Messaging Center ⚡ ⚡ 🚀\nParamters, Cascading Parameters and Event Callbacks are ways to send data across components but MessagingCenter is much easier and straightforward\n![MessagingCenter](https://github.com/aksoftware98/blazor-utilities/blob/main/Assets/MessagingCenter%20Sample.gif?raw=true)\n\n\nIf you are a Xamarin.Forms developer, you definitely passed across the MessagingCenter class that was being used to send messages across objects, this class helps a lot by pushing data across components in the system effiecently. \nAnd now for Blazor Messaging Center is a great tool to use to solve the issue of sending the data across components and updating them.\nUsing MessagingCenter you will be able to send data from one component to another or to a set of other components just with one line of code despite the relationship between those components (Parent - Child .etc...)\nThe following illustration shows the benefits of using MessagingCenter to send data between the components.\n\n### Messaging Center Quick Explanation:  \n![enter image description here](https://github.com/aksoftware98/blazor-utilities/blob/main/Assets/MessagingCenter.png?raw=true)\n## Package Content:  \nFor now package the **AKSoftware.Blazor.Utilities** just contains the ***MessagingCenter*** service which is the same that is implemented in Xamarin.Forms to be used in Blazor projects as a service to send the data across the components using the Publish - Subscription pattern in addition to the existing model of Parameters \u0026 Event Callbacks.\n\n\u003e **Note:** The messaging center class with the current package is the same class and cloned from the Xamarin.Forms repository from the following link [Xamarin.Forms](https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Core/MessagingCenter.cs)\n\n## Check out the sample project:\nIn the current repository you can find a sample project to use the MessagingCenter service in Blazor that shows how to send a string value from one component to two other components without a direct relationship between them and update their states. \nThe example shows using updating the username in a form component then using MessagingCenter we can send that update to the NavMenu component and the MainLayout and update the value there. \nCheck out the following folder: \n\n## 🌎 👷 Get Started with Blazor MessagingCenter ⛳\nMake sure to instal the NuGet package of the library using the ***NuGet command*** \n``` \n\tInstall-Package AKSoftware.Blazor.Utilities\n```\n\nOr through the ***.NET CLI***\n```\n\tdotnet package install AKSoftware.Blazor.Utilities\n```\n\nNow in the **_imports.razor** and add the following namesapce\n``` Razor\n@using AKSoftware.Blazor.Utilities\n```\n\n## ⚡  🚀 Publish a message  🚀 ⚡\nFrom the component that you want to send data from example a sample string like the example in the repository \n\n\u003e The code takes a the sender object as a parameter, the filter of the message like for this example \"greeting_message\" which will be used by other components to receive the message, and the last parameter is the value to be sent\n\n``` C#\npublic void SendMessage()\n{\n     string valueToSend = \"Hi from Component 1\";\n     MessagingCenter.Send(this, \"greeting_message\", valueToSend);\n}\n```\n\n## ✈️ Receive a message from destination component ✈️\n\nIn the destination component all you can do is calling the subscribe method to subscribe for a target of messaging \n\nBlazor WebAssembly\n\n``` C#\npublic void SubscribeToMessage()\n{\n\tMessagingCenter.Subscribe\u003cComponent1, string\u003e(this, \"greeting_message\", (sender, value) =\u003e \n\t{\n\t\t// Do actions against the value \n\t\t// If the value is updating the component make sure to call \n\t\tstring greeting = $\"Welcome {value}\";\n\t\tStateHasChanged(); // To update the state of the component \n\t});\n}\n```\n\n## 🚧⚠️ Blazor Server Notice 🚧⚠️\n\nBecuase Blazor Server working on thread make sure to call that InvokeAsync within the callback\n**Note:** This will be resolved and updated in the version 1.0.1 \nSpecial thanks for **[Ferenc Czirok](https://github.com/czirok)** for mentioning the note and the following code snippet\n\n``` C#\npublic void SubscribeToMessage()\n{\n\tMessagingCenter.Subscribe\u003cComponent1, string\u003e(this, \"greeting_message\", async (sender, value) =\u003e \n\t{\n\t\t// Do actions against the value \n\t\t// If the value is updating the component make sure to call \n\t\t// Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state\n\t\tawait InvokeAsync(() =\u003e {\n\t\t\tstring greeting = $\"Welcome {value}\";\n\t\t\tStateHasChanged(); // To update the state of the component \n\t\t});\n\t});\n}\n```\n\n### Enjoy it 🎢\n\n## 🚧 How to contribute\nContributions are welcomed to the current repository you can get started by \n\n - Cloning the project\n - Add your own features \n - Submit a PR \n - You can find me here https://ahmadmozaffar.net\n\n## ⚠️ You have problems???\nFeel free to open any issue directly from the issues section here [GitHub Issues](https://github.com/aksoftware98/blazor-utilities/issues)\n\n\n#### Developed with all ❤️ by 💻 [Ahmad Mozaffar](https://ahmadmozaffar.net)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faksoftware98%2Fblazor-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faksoftware98%2Fblazor-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faksoftware98%2Fblazor-utilities/lists"}