If you have a class similar to the following:
public class MyClass
{
public async Task MyMethod(string param)
{
//Do Work...
}
public string MyProperty { get; set; }
}
Subscribe with a Token, Target object, and Method Name, like this:
var myClass = new MyClass()
await mediator.RegisterSubscriber("token", myClass, "MyMethod");
await mediator.RegisterSubscriber("tokenProperty", myClass, "MyProperty");
or this way using reflection to get the MethodInfo for the method that will receive the messages:
var methodInfo = myClass.GetType().GetTypeInfo().DeclaredMethods("MyMethod");
await mediator.RegisterSubscriber("token", myClass, myMethodInfo);
you can also pass an anonymous action as a lambda like so:
await mediator.RegisterSubscriber("token", (string param) => { Console.WriteLine("Message Received: {0}", param); });
lastly, you can pass an anonymous function that returns a value, the syntax is a bit different than for an action as you need to pas the source of the function:
await mediator.RegisterSubscriber("token", this, (string param) => { return param; });