Dev @ Work

A day in the life of a developer

Castle Windsor Component Messaging: Senders & Receivers

June 12th, 2007 by Trilobyte

Here is some more information about the messaging framework I have been working on the last couple of weeks. Although I had less time to work on the framework then I had expected, I managed to get some work done on message filtering, but that is a subject for a next post.

In this post I will explain how you implement a message sender and receiver class. I tried to keep the framework as simple as possible and I think I did a pretty good job, however if you have any comments or ideas, please let me know.

Anyway, enough talk, lets get down to business.

Implementing a message sender

Implementing a sender is very easy, there are two things to do: The first step is to implement the IMessageSender interface or derive from the SenderBase class. Then you need to decorate the sender class with the MessageSenderAttribute. That is it.

Example:

[MessageSender()]
public class TestSender: SenderBase
{
	public void SendMessage()
	{
		TestMessage msg = new TestMessage();
		base.DoSend(msg);
	}
}

The TestMessage which is send in the example code does not contain any information, but you can define your own message class which contains any information you can imagine.

Implementing a message receiver

The implementation of a receiver class is not equal easy as the implementation of the sender class. There are two steps as well: The first step is to implement the IMessageReceiver interface and the second step is to decorate the class with the MessageReceiverAttribute.

Example:

[MessageReceiver()]
public class TestReceiver: IMessageReceiver
{
	public void Receive(IMessage message)
	{
		// do something with the message
	}
}

The receive function will be called when a message is received.

Currently I am working on the implementation of the message filters. The idea is that you can do pre-processing on messages using some clean C# constructs. When I got an implementation ready I will post it on this weblog. That is it for now. See you next time.

Internal Messaging for Castle IoC Components

June 1st, 2007 by Trilobyte

At the moment I am working on a framework which provides loose coupled internal messaging support for components that live in the Castle Windsor IoC container. This messaging framework stimulates the decoupling of components by providing loose coupled messages.

The messages can be sent from any component that is declared to be a message sender to any component that is declared to be a message receiver. The components, for the senders, do not know to which components receive the message or, for the receivers, where the message originated from.

The messages contain Meta information describing the payload of the message. Currently I am working on the messages themselves. Here is an example of how you can extract information from a message without knowing its explicit content.

Firs we will create a message and its payload:

// creating the message and it's payload
Person person1			= new Person("Bert");
IContentMetaInfo metaInfo1	= new ContentMetaInfoBase(typeof(Person));
IContent content1			= new ContentBase(person1, metaInfo1);
Person person2			= new Person("Trilobyte");
IContentMetaInfo metaInfo2	= new ContentMetaInfoBase(typeof(Person));
IContent content2			= new ContentBase(person2, metaInfo2);
MessageBase msg			= new MessageBase(new IContent[] {content1,content2});

Image the message is send to somewhere and then take a look at the receive code below:

// get the payload from the message
foreach (IContent personContent in msg.FindContentByMetaInfo(delegate (IContentMetaInfo inf) {return inf.ContentType == typeof(Person);}))
{
	// process the person content
	Person p	= (Person)personContent.Content;
	Console.WriteLine(p.Name);
}

As you can see, I only extracted the data I discovered, for all I know the message contains tons of other information, but I do not care about that.

Although my current implementation is not completed yet and there is a lot of stuff still to do, I really wanted to share this sample with you, because I think this method is a good way to decrease coupling between components in the system.

I will keep working on the framework as much as I can, so expect more information about it soon. In the mean time reactions about ideas, questions or comments are very welcome!

Inversion of Control

March 26th, 2007 by Trilobyte

Ik ben sinds enige tijd bezig met het ontwikkelen van een softwarepakket met behulp van een Inversion of Control container en ik ben er erg enthousiast over, vandaar deze post.

Read the rest of this entry »