|
Hi Guirec! Cool that you're giving MiniBuss a try!
1. The reason for the Reply method is mostly to get a nice programming experience I would say. It also gives you the chance to perhape easier control responses to specific commands. I'm not sure exactly what you are asking, but you can look at the sample
code on this site.
2. You are right, but the reason the interface looks like that is that it makes it easier to write the code for the action because the command gets typed. With your suggested method interface for RegisterMessageHandler, you would have to cast the command
object to use it in the handler code.
Now you can do:
bus.RegisterMessageHandler<HelloCommand>(command =>
{
Console.WriteLine("Got command: {0} Guid: {1}, Number: {2}",
command.Message, command.Guid, command.Number);
});
With your suggestion, one would have to do:
bus.RegisterMessageHandler(typeof(HelloCommand),cmd =>
{
var command = (HelloCommand) cmd;
Console.WriteLine("Got command: {0} Guid: {1}, Number: {2}",
command.Message, command.Guid, command.Number);
});
It's not too bad, and it's very easy for you to make the changes yourself to the code if you like. Or add it to the codebase in a partial class with something like this (not tested ;):
public partial interface IServiceBus
{
void RegisterMessageHandler(Type typeOfCommand, Action<object> handler);
void RegisterMessageEndpoint(Type typeOfCommand, string targetEndpoint);
}
public partial class ServiceBus : IServiceBus
{
public void RegisterMessageHandler(Type typeOfCommand, Action<object> handler)
{
_messageHandlers[typeOfCommand] = handler;
}
public void RegisterMessageEndpoint(Type typeOfCommand, string targetEndpoint)
{
_targetQueues[typeOfCommand.TypeHandle] = GetEndpointName(targetEndpoint);
}
}
Question for you - you mentioned autoregistration. Can you explain a bit more what you had in mind? Sounds interesting because I have some experimental code which does just that.
|