Command Handling the Nancy Way
MiniBuss is a micro service bus framework over msmq which consists of less than 400 lines of code, sitting inside one single source file. The project is hosted over at http://minibuss.codeplex.com and the source code is maintained at https://github.com/johandanforth/MiniBuss
I’ve been a fan of the Sinatra inspired web framework called Nancy, especially the neat way of setting up handlers for routes. The simplest sample on their site is this:
public class Module : NancyModule
{
public Module()
{
Get["/greet/{name}"] = x => {
return string.Concat("Hello ", x.name);
};
}
}
So, I shamelessly dug into the Nancy code and borrowed some 20-30 lines of code and came up with something like this for registering handlers for certain incoming commands on the minibus, what do you think?
public class CommandHandler : MessageHandler
{
public CommandHandler()
{
WhenReceiving[typeof(SampleMessage1)] = x =>
{
Console.WriteLine("sample 1 message: " + x.Text);
};
WhenReceiving[typeof(SampleMessage2)] = x =>
{
Console.WriteLine("sample 2 message: " + x.Text);
};
}
}
It’s a bit more code but it helps/enforces you to move the handlers off to a certain module. Thoughts?