AKSoftware.Blazor.Utilities
1.0.0
See the version list below for details.
dotnet add package AKSoftware.Blazor.Utilities --version 1.0.0
NuGet\Install-Package AKSoftware.Blazor.Utilities -Version 1.0.0
<PackageReference Include="AKSoftware.Blazor.Utilities" Version="1.0.0" />
paket add AKSoftware.Blazor.Utilities --version 1.0.0
#r "nuget: AKSoftware.Blazor.Utilities, 1.0.0"
// Install AKSoftware.Blazor.Utilities as a Cake Addin #addin nuget:?package=AKSoftware.Blazor.Utilities&version=1.0.0 // Install AKSoftware.Blazor.Utilities as a Cake Tool #tool nuget:?package=AKSoftware.Blazor.Utilities&version=1.0.0
Welcome to Messaging Center Blazor Utitlity!
AKSoftware.Blazor.Utilities
⚡ ⚡ 🚀 Send data across your components fluently with the Messaging Center ⚡ ⚡ 🚀
Paramters, Cascading Parameters and Event Callbacks are ways to send data across components but MessagingCenter is much easier and straightforward
If 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. And now for Blazor Messaging Center is a great tool to use to solve the issue of sending the data across components and updating them. Using 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...) The following illustration shows the benefits of using MessagingCenter to send data between the components.
Package Content:
For 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 & Event Callbacks.
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
Check out the sample project:
In 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. The 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. Check out the following folder:
🌎 👷 Get Started with Blazor MessagingCenter ⛳
Make sure to instal the NuGet package of the library using the NuGet command
Install-Package AKSoftware.Blazor.Utilities
Or through the .NET CLI
dotnet package install AKSoftware.Blazor.Utilities
Now in the _imports.razor and add the following namesapce
@using AKSoftware.Blazor.Utilities
⚡ 🚀 Publish a message 🚀 ⚡
From the component that you want to send data from example a sample string like the example in the repository
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
public void SendMessage()
{
string valueToSend = "Hi from Component 1";
MessagingCenter.Send(this, "greeting_message", valueToSend);
}
✈️ Receive a message from destination component ✈️
In the destination component all you can do is calling the subscribe method to subscribe for a target of messaging
public void SubscribeToMessage()
{
MessagingCenter.Subscribe<Component1, string>(this, "greeting_message", (sender, value) =>
{
// Do actions against the value
// If the value is updating the component make sure to call
string greeting = $"Welcome {value}";
StateHasChanged(); // To update the state of the component
});
}
Enjoy it 🎢
🚧 How to contribute
Contributions are welcomed to the current repository you can get started by
- Cloning the project
- Add your own features
- Submit a PR
- You can find me here https://ahmadmozaffar.net
⚠️ You have problems???
Feel free to open any issue directly from the issues section here GitHub Issues
Developed with all ❤️ by 💻 Ahmad Mozaffar
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.AspNetCore.Components.Web (>= 5.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
The first version that contains the support for the MessagingCenter class to be used to send data across components effeciently