AKSoftware.Blazor.Utilities 1.0.0

.NET 5.0
dotnet add package AKSoftware.Blazor.Utilities --version 1.0.0
NuGet\Install-Package AKSoftware.Blazor.Utilities -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AKSoftware.Blazor.Utilities" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AKSoftware.Blazor.Utilities --version 1.0.0
#r "nuget: AKSoftware.Blazor.Utilities, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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!


⚡ ⚡ 🚀 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

⚠️ 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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 7,448 10/2/2021

The first version that contains the support for the MessagingCenter class to be used to send data across components effeciently