Yes. No mediator is required.
Assume the following interface:
public interface ICommandHandler<in TCommand> where TCommand : ICommand
{
void Execute(TCommand command);
}
Now you have the following command:
public class CreateCustomer : ICommand { /* ... */ }
And a controller (example from ASP.NET MVC):
public CustomerController
{
CustomerController(ICommandHandler<CreateCustomer> handler) { Handler = handler; }
public ActionResult CreateCustomer(CreateCustomer model)
{
if (!ModelState.IsValid) { return View(); }
Handler.Execute(model);
return View();
}
}
The dependency injection will handle the creation of the command handler. If you want to apply additional behavior (e.g. logging) to the command execution, you can implement an interceptor within the dependency injection. The object could be a decorator including the orgiginal command handler or a proxy submitting the command to web service. All OOP stuff is possible via injection.
An alternative could be a factory pattern:
public ActionResult CreateCustomer(CreateCustomer model)
{
var handler = HandlerFactory.CreateHandlerFor<CreateCustomer>();
handler.Execute(model);
return View();
}
Works fine (if you like factories).
A mediator is just a way to decouple two objects. The advantage is you just have to inject the mediator instead of multiple required command handlers (in comparision to the dependency injection) and you do not have to hold a local copy of the created command handler (in comparision to the factory pattern).
But a mediator has also disadvantages. For instance you cannot control, that the CustomerController calls the command CreateProduct. By injection only specific command handlers, you can limit the commands a controller can create (if you want to).