Dev @ Work

A day in the life of a developer

Interception Magic

September 27th, 2007 by Trilobyte

Hello, how are you? I am fine, thanks for asking. :S, anyway, in this post I will tell you about my first experience… with Windsor Castle interceptors that is. This morning, way to early, I tried to solve an access control problem: I needed to protect several WCF web services from unauthorized users. I was not very awake at the time so I came up with an easy, yet elegant, solution: use interceptors.

What are interceptors you might think, well, interceptors are class which intercept method calls for other classes. The purpose is to implement a common action, like: logging or authorization, they basically act as proxies. Castle Windsor allows you to configure interceptors in the application configuration file which solved my problem of having to modify all the service code myself.

Writing an interceptor for the Castle Windsor container is actually a simple and straightforward process: Create a new class and implement the IInterceptor interface which defines one single method: Intercept(IInvocation). The only thing left to do is to configure the component on which you want to apply the interceptor. That is it.

I am not going to explain all the details now, however I might write an article in the near future. That is it for now, until 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 »