Comments (6)
maybe we should ask @lbugnion if this change is good for a PR!
from mvvmlight.
You could override the default messenger (Messenger.OverrideDefault) with your own implementation of IMessenger that just forwards the method calls to an internal Messenger object and add some custom actions...
Regards,
abgenullt
from mvvmlight.
@abgenullt Thanks for the reply. Can you give me some pointers as to where and how I would do this?
Thanks
from mvvmlight.
You could create a class like this:
public class MyMessenger : IMessenger
{
/// <summary>
/// Messenger, that will do the real work.
/// </summary>
private readonly Messenger _internalMessenger;
/// <summary>
/// This method will be called from the send methods.
/// </summary>
private void CustomeSendAction<TMessage>(TMessage msg)
{
Console.WriteLine($"Message: {msg} sent.");
}
public MyMessenger()
{
_internalMessenger = new Messenger();
}
public void Register<TMessage>(object recipient, Action<TMessage> action, bool keepTargetAlive = false)
{
_internalMessenger.Register(recipient, action, keepTargetAlive);
}
public void Register<TMessage>(object recipient,
object token,
Action<TMessage> action,
bool keepTargetAlive = false)
{
_internalMessenger.Register(recipient, token, action, keepTargetAlive);
}
public void Register<TMessage>(object recipient,
object token,
bool receiveDerivedMessagesToo,
Action<TMessage> action,
bool keepTargetAlive = false)
{
_internalMessenger.Register(recipient, token, receiveDerivedMessagesToo, action, keepTargetAlive);
}
public void Register<TMessage>(object recipient,
bool receiveDerivedMessagesToo,
Action<TMessage> action,
bool keepTargetAlive = false)
{
_internalMessenger.Register(recipient, receiveDerivedMessagesToo, action, keepTargetAlive);
}
public void Send<TMessage>(TMessage message)
{
CustomeSendAction(message);
_internalMessenger.Send(message);
}
public void Send<TMessage, TTarget>(TMessage message)
{
CustomeSendAction(message);
_internalMessenger.Send<TMessage, TTarget>(message);
}
public void Send<TMessage>(TMessage message, object token)
{
CustomeSendAction(message);
_internalMessenger.Send(message, token);
}
public void Unregister(object recipient)
{
_internalMessenger.Unregister(recipient);
}
public void Unregister<TMessage>(object recipient)
{
_internalMessenger.Unregister(recipient);
}
public void Unregister<TMessage>(object recipient, object token)
{
_internalMessenger.Unregister<TMessage>(recipient, token);
}
public void Unregister<TMessage>(object recipient, Action<TMessage> action)
{
_internalMessenger.Unregister(recipient, action);
}
public void Unregister<TMessage>(object recipient, object token, Action<TMessage> action)
{
_internalMessenger.Unregister(recipient, token, action);
}
}
.. And add this line to the static constructor of the ViewModelLocator replace the default messenger:
Messenger.OverrideDefault(new MyMessenger());
from mvvmlight.
@abgenullt @MrYossu What about a simpler approach? I've forked the repo and added a method called AddVerboseMessageHandler
that takes in input an Action<object>
and only when debugging and when set the messenger invokes it passing the TMessage
as input. See commit
from mvvmlight.
@GiancarloLelli Thanks for that, that was very nice of you!
How do I use this fork though? We have MVVMLight installed as a Nuget package, we don't include the source in our code, so I can't just replace that one file.
Thanks again.
from mvvmlight.
Related Issues (20)
- In 2021, should we still using this library? HOT 2
- Source code for MvvmLightLibsStd10 v5.4.1.1 package
- Build Warning XA0125
- View not updated when setting properties from within RelayCommand execution HOT 2
- Intermittent 'enumeration modified' exception in SendToTargetOrType() HOT 1
- System.OutOfMemoryException when trying to send message HOT 2
- AndroidX migration HOT 10
- Weirdness while usage MVVM light 5.4.1.1 HOT 1
- Could anyone suggest a neat way to Dis-/Enable buttons HOT 3
- Feedback requested on generated WPF projects using MVVMLight in Windows Template Studio
- How to use “EventToCommand” in ".Net Standard 1.0" Version of "MVVM Light"?
- Modifiing property from INotifyPropertyChanged Class after GoToAsync -> Pop -> GoToAsync result in ObjectDisposedException HOT 1
- EventTo Command: difference (advantages/ disadvantages). Can't see. HOT 1
- .NET Core Support HOT 9
- VSIX packages for Visual Studio 2019 -Link in #75 not wokring
- MvvmLight 5.4.1.1 source code HOT 1
- SimpleIoc is no longer inherited from IServiceLocator in Std10 version. HOT 2
- WPF: A proper way to execute method when property became true or false. HOT 1
- MvvmLight with Microsoft.Xaml.Behaviours - Unable to use behaviour assets HOT 1
- Use Messenger,One Page with different data viewmodel ,will Error correspondence
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mvvmlight.