Documentation
NServiceBus is comprised of multiple packages, several of which are made primarily
of interfaces, others which implement those interfaces using a given technology.
NServiceBus.Core is the central package defining interfaces which applicative code
will use for communication. The classes and interfaces in this package are shown
in the following diagram:
The interface IMessage is a marker interface which all applicative messages will
implement. It is also important that applicative messages are marked with the Serializable
attribute so that they can be serialized across transports performing inter-process
and inter-machine communication.
The interface IMessageHandler<T> is to be implemented by classes containing
logic dictating how a message is to be handled. Classes can choose to implement
this interface for a concrete applicative message like so:
public class AddOrderMessageHandler : IMessageHandler<AddOrderMessage>
{
public void Handle(AddOrderMessage message)
{
// applicative code
}
}
Classes can also choose to implement the IMessageHandler interface on "generic"
message types represented by interfaces. These interfaces can be simply IMessage,
or some applicative interface which multiple applicative messages implement. In
cases where the class should handle every message (say for auditing purposes), use
the message type IMessage like so:
public class AuditingMessageHandler : IMessageHandler<IMessage>
{
public void Handle(IMessage message)
{
// code that will
audit every message arriving at this endpoint
}
}