Callback notation in a Mediator I'm implementing a Mediator and I'd like to simplify the callback notation a bit.

My mediator has Register and Notify methods :

public class Mediator {
    private Dictionary&lt;Messages, Action&lt;object&gt;&gt; registeredCallback;

    public void Register(Messages message, Action callback) {
        registeredCallback[message] = callback;
    }

    public void Notify(Messages message, object parameter) {
        callback(parameter);
    }

    public Mediator() {
        registeredCallback = new Dictionary&lt;Messages, Action&lt;object&gt;&gt;();
    }
}


It uses a Messages enumerator to sanitize events between registered objects, for example :

public enum Messages {
    UserCreated,
    UserDeleted,
    UserChangedPassword
};


So far, so good. However, when I use this mediator I'm making ugly callback definitions :

mediator.Register(Messages.UserCreated, (object user) =&gt; GreetUser(((User)user).name));


with the following User:

public class User {
    public string name;
}


Type casting? Lambda expressions? This looks obviously filthy. How can I clean this up? Is my architecture at fault?
What about making the Register method generic?

public class Mediator
{
    private Dictionary&lt;Messages, Action&lt;object&gt;&gt; registeredCallback =
        new Dictionary&lt;Messages, Action&lt;object&gt;&gt;();

    public void Register&lt;TParam&gt;(Messages message, Action&lt;TParam&gt; callback)
    {
        registeredCallback[message] = p =&gt; callback((TParam)p);
    }

    public void Notify(Messages message, object parameter)
    {
        callback(parameter);
    }
}


The typecasting is done inside the Register method, making it invisible to any class using it.

You can also change signature of the GreetUser method so that it takes a User instead of a string as a parameter. By doing so you can call Register like this:

mediator.Register&lt;User&gt;(Messages.UserCreated, GreetUser);