Project Description
This library simplifies the process of executing code on a different thread and separating the caller from the actual command logic. To do this messages are put into an execution module and the library automatically calls the target message handlers.

The goal of the library is to have a working module with little to no configuration. In this way it is is greatly inspired by NServiceBus. This library has a similar feel but works purely in-process. The engine automatically calls message handlers which handle either a specific message, a base class or interface. Multiple handlers may exist for the same message. For simple tasks there is also an overload to execute an Action delegate. Message handlers are either executed on a single worker thread or on a custom number of workers.

The library is using dependency injection. This allows for an easy way to add external dependencies into your message handlers to perform their task. Additionally, it makes it easy to tweak and extend the library without having to edit the source itself.

Basic Usage:
Using the library is simple. First define a message to be used. This can be any .NET class. (In previous versions messages had to inherit from IMessage).

public class CreateReportMessage
{
  public string Title { get; set; }
}
Next create a message handler. This is achieved by inheriting a class from IMessageHandler<T>. This handler will be created and called every time a message is received matching the handler definition.

public class CreateReportHandler : IMessageHandler<CreateReportMessage>
{
  public void Handle(CreateReportMessage message)
  {
    Console.WriteLine("Writing Report: {0}", message.Title);
  }
}
The message has to be put into the execution engine. To do this an instance of IExecutionModule has to be configured and obtained. The instance of IExecutionModule is put into the target dependency injection container. This means after the initial configuration it can easily be requested by any custom object instance which wants to send a message to the lib.

public static void Main()
{
  // configures the module to use StructureMap as injection container,
  // otherwise use library defaults.
  IExecutionModule execModule = Module.Configure()
                           .UseStructureMap()
                           .Build();

  // create a custom message and fill it with data.
  var msg = new CreateReportMessage { Title = "Report Title" };

  // add the message into the execution module.
  execModule.Add(msg);

  // message handler will be executed on a separate thread,
  // wait until execution has finished.
  Console.WriteLine("Press any key to quit.");
  Console.ReadKey();
}

Last edited Jul 15, 2012 at 10:16 AM by domo42, version 29