<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dev @ Work &#187; Castle Project</title>
	<atom:link href="http://www.devatwork.nl/tag/castle-project/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devatwork.nl</link>
	<description>A day in the life of a developer</description>
	<lastBuildDate>Tue, 18 Oct 2011 16:32:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Breadcrumbs Framework Sample</title>
		<link>http://www.devatwork.nl/2007/10/breadcrumbs-framework-sample/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=breadcrumbs-framework-sample</link>
		<comments>http://www.devatwork.nl/2007/10/breadcrumbs-framework-sample/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 10:08:07 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[MonoRail]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Breadcrumbs]]></category>
		<category><![CDATA[Castle Project]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/10/10/breadcrumbs-framework-sample/</guid>
		<description><![CDATA[You can view an online sample of the breadcrumb framework for Monorail.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.devatwork.nl/wp-content/uploads/2007/10/breadcrumbs.jpg" alt="Breadcrumbs" class="leftimage" /></p>
<p>Yesterday, I mentioned in my post about MonoRail that I would make the source of the framework available to the community. Today I found some time to build a sample application demonstrating the framework.</p>
<p>You can view the sample application by navigating to: <a href="http://breadcrumbs.premotion.nl" title="Sample Application">http://breadcrumbs.premotion.nl</a> and you can get the source by clicking here: <a href="http://www.devatwork.nl/wp-content/uploads/2007/10/breadcrumbs.zip" title="Sample Sourcecode">Download here</a>. The framework is by no means complete or stable and <strong>must not</strong> be used in any other application than test applications. Neither me nor Premotion can be held responsible for damage caused by the usage of the framework.</p>
<p>I know the framework contains a lot of bugs, but I am not going to fix them before I have a clear idea of what features the framework should contain. If you have any suggestions, ideas or comments, please let me know!</p>

	Tags: <a href="http://www.devatwork.nl/tag/breadcrumbs/" title="Breadcrumbs" rel="tag">Breadcrumbs</a>, <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/monorail/" title="MonoRail" rel="tag">MonoRail</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/10/breadcrumbs-framework-sample/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monorail in a Castle</title>
		<link>http://www.devatwork.nl/2007/10/monorail-in-a-castle/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monorail-in-a-castle</link>
		<comments>http://www.devatwork.nl/2007/10/monorail-in-a-castle/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 08:57:49 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Castle Project]]></category>
		<category><![CDATA[MonoRail]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Breadcrumbs]]></category>
		<category><![CDATA[Rapid Application Building]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/10/09/monorail-in-a-castle/</guid>
		<description><![CDATA[This post is not about some train riding one single track and a big fortified building but about the Monorail MVC (Model View Controller) framework of the Castle Project. This is not going to be an introduction to Monorail but rather a story about my workflow for this particular project. Although I might write an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.devatwork.nl/wp-content/uploads/2007/10/mr_rawlogo.gif" alt="Castle Monorail" class="leftimage imagenoborder" /></p>
<p>This post is not about some train riding one single track and a big fortified building but about the Monorail MVC (Model View Controller) framework of the Castle Project.</p>
<p>This is not going to be an introduction to Monorail but rather a story about my workflow for this particular project. Although I might write an article about Monorail in the future, for now I will point you to the Castle Project website for information about Monorail.</p>
<p>Last week I had to build a web application for the Van der Werff project, which allows users to view project information online and report malfunctions. The access to the information must be protected from anonymous users and only be accessible for authenticated users. The project information comes from the WCF web service, which also provides the security.</p>
<p>In the next paragraphs you can read how I implemented the application.</p>
<p><span id="more-72"></span></p>
<h2>Functional Structure</h2>
<p>The application has the following structure:</p>
<ul>
<li>Home</li>
<li>Contact form</li>
<li>
		Projects</p>
<ul>
<li>Project information</li>
<li>
				Addresses</p>
<ul>
<li>Address information</li>
<li>Product information</li>
<li>Checklist information</li>
<li>Report malfunction form</li>
</ul>
</li>
</ul>
</li>
<li>Login</li>
</ul>
<h2>Logical Structure, Controllers &#038; Actions</h2>
<p>I started dividing the application functionality into logical groups which became the controllers and each bit of functionality became one or more actions.</p>
<p>The result is:</p>
<ul>
<li>
		Home Controller</p>
<ul>
<li>Home</li>
<li>Contact form</li>
<li>Contact form ‘thank you’</li>
</ul>
</li>
<li>
		ProjectView Controller</p>
<ul>
<li>List projects</li>
<li>View project</li>
<li>View address</li>
<li>View product</li>
<li>View checklist</li>
<li>Report malfunction form</li>
<li>Report malfunction form ‘thank you’</li>
</ul>
</li>
<li>
		Login Controller</p>
<ul>
<li>Login form</li>
<li>Logout</li>
</ul>
</li>
</ul>
<h2>Home Controller</h2>
<p>The home controller was the simplest controller to implement, it contains only three actions. The first action ‘Home’ does nothing more than to render the homepage. The second action ‘Contact form’ renders the contact form. The third action is more interesting, it gathers the information from the ‘Contact form’ validates it and sends it as an e-mail to the configured address.</p>
<p>This was the first time I used the e-mail sender service of the Monorail framework but it was a joy to work with. You can store anything in the <em>PropertyBag</em> and then render an e-mail template like you would with a normal view. After rendering you get a <em>Message</em> object back which you can send.</p>
<p>Here is some sample code:</p>
<pre class="brush: csharp; title: ; notranslate">// set the properties
PropertyBag[&quot;from&quot;]    = Settings.ApplicationMailAddress;
PropertyBag[&quot;to&quot;]      = Settings.ContactMessageDeliverAddress;
PropertyBag[&quot;name&quot;]    = name;
PropertyBag[&quot;phone&quot;]   = phone;
PropertyBag[&quot;mail&quot;]    = mail;
PropertyBag[&quot;subject&quot;] = Settings.ContactMessageSubject;
PropertyBag[&quot;message&quot;] = message;

// send the message
Message msg = this.RenderMailMessage(Settings.ContactMessageTemplate);
msg.From    = Settings.ApplicationMailAddress;
msg.To      = Settings.ContactMessageDeliverAddress;
msg.Subject = Settings.ContactMessageSubject;
this.DeliverEmail(msg);</pre>
<p>The <em>RenderMailMessage()</em> function does all the magic of rendering an e-mail template and creating a <em>Message</em> object out of it.</p>
<p>After the message is send, the user is redirected to a nice ‘thank you’ view.</p>
<h2>Login Controller</h2>
<p>The login controller container, do not be surprised, the login functionality. The controller does nothing more than to render the login form, check if the user name and password are valid string (the real authentication is done by the WCF back-end web service), store them in the session and destroy the session when the user logs out.</p>
<h2>Project View Controller</h2>
<p>The project view controller was surpassingly easy to implement. It does nothing more than retrieving data, managing identifiers and to render the correct view. Actually it does a little more than that: It manages caching and also contains an e-mail form which allows the user to report a malfunction. The functionality is similar to the ‘Contact form’ functionality.</p>
<p>But it really surprised me how simple it is to create such an application. If I had used ASP.NET or PHP it would have cost me a lot more time.</p>
<h2>Time</h2>
<p>Speaking of time, it took about three 8 hour days to implement the application. That includes writing the style and html layout as well as deploying the application to the server. Some people might still think that 24 hours is too long, but remember: There was a learning curve, for example: I did not know how to use the mail sender service.</p>
<p>Another aspect that cost more time than it could have was: breadcrumbs. I could have hardcoded them, saving myself about 8 hours, but I choose to write a framework to handle them.</p>
<h2>Breadcrumb Framework</h2>
<p>The breadcrumb framework contains some classes to allow me to define breadcrumb paths easily. Each action can be decorated with a Breadcrumb attribute. An interceptor checks if an action is decorated with the attribute and adds it to a manager class if it does. Then on the view I can use a <em>ViewComponent</em> which renders the breadcrumb path. Simple, clean, nice!</p>
<p>Although the framework needs a lot of tuning, it something I am considering donating to the Castle framework. I just hope I can find the time to do it.</p>
<h2>Conclusion</h2>
<p>Castle Monorail is a powerful MVC framework which allows it users to develop web applications rapidly. It is very extensible as well: Most, if not all, components can be swapped out and be replaced by others.</p>
<p>The integration with Castle MicroKernel makes it even easier to develop complex applications. Combine it advantages with its ever growing user base/developers base and you have yourself a winner, well that is my opinion anyway <img src='http://www.devatwork.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>That is it for this post. I hope you enjoyed the read, if you did, please let me know and if you did not, please let me know too. Bye</p>
<h3>Sources</h3>
<ol class="sourcelist">
<li>[1] <a href="http://www.castleproject.org/monorail/" title="Castle Monorail">Castle Monorail</a></li>
<li>[2] <a href="http://www.castleproject.org/" title="The Castle Project">Castle Project</a></li>
<li>[3] <a href="http://www.castleproject.org/container/" title="Castle MicroKernel">Castle MicroKernel</a></li>
</ol>

	Tags: <a href="http://www.devatwork.nl/tag/breadcrumbs/" title="Breadcrumbs" rel="tag">Breadcrumbs</a>, <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/monorail/" title="MonoRail" rel="tag">MonoRail</a>, <a href="http://www.devatwork.nl/tag/rapid-application-building/" title="Rapid Application Building" rel="tag">Rapid Application Building</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/10/monorail-in-a-castle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interception Magic</title>
		<link>http://www.devatwork.nl/2007/09/interception-magic/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=interception-magic</link>
		<comments>http://www.devatwork.nl/2007/09/interception-magic/#comments</comments>
		<pubDate>Thu, 27 Sep 2007 18:54:01 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Castle Project]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Windsor Container]]></category>
		<category><![CDATA[Interceptors]]></category>
		<category><![CDATA[MicroKernel]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/09/27/interception-magic/</guid>
		<description><![CDATA[In this post I will tell you about my first experience with interceptors and Aspect Oriented Programming using Castle Windsor.]]></description>
			<content:encoded><![CDATA[<p>Hello, how are you? I am fine, thanks for asking. :S, anyway, in this post I will tell you about my first experience&#8230; 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.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>

	Tags: <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/interceptors/" title="Interceptors" rel="tag">Interceptors</a>, <a href="http://www.devatwork.nl/tag/microkernel/" title="MicroKernel" rel="tag">MicroKernel</a>, <a href="http://www.devatwork.nl/tag/windsor-container/" title="Windsor Container" rel="tag">Windsor Container</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/09/interception-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rapid Application Building</title>
		<link>http://www.devatwork.nl/2007/08/rapid-application-building/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rapid-application-building</link>
		<comments>http://www.devatwork.nl/2007/08/rapid-application-building/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 09:39:33 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Active Record]]></category>
		<category><![CDATA[Castle Project]]></category>
		<category><![CDATA[MonoRail]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Rapid Application Building]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/08/20/rapid-application-building/</guid>
		<description><![CDATA[I had to wrote a simple web application which enabled the user to list, create, update and delete fairly simple log entries using Castle MonoRail and Castle ActiveRecord in less then one hour.]]></description>
			<content:encoded><![CDATA[<p>In the previous hour I wrote a real simple web application with the purpose of CRUD (Create, Read, Update and Delete) log entries. When you use ASP.NET and ADO.NET that would typically take a couple of hours. First you would have to create the database scheme then you would have to write the business logic and finally you need to create the pages.</p>
<p>However I decided to leverage the power of some components of the Castle project [<a href="#1">1</a>]: Castle MonoRail [<a href="#2">2</a>] and Castle ActiveRecord [<a href="#3">3</a>]. Castle Monorail is a MVC (Model View Controller) framework and Castle ActiveRecord is a framework based on the active record[<a href="#4">4</a>] pattern. The components integrate very nicely as you will see.</p>
<p><span id="more-65"></span></p>
<p>First I created the log entry active record class which is a simple POCO (Plain Old CLR Object), derived it from <em>ActiveRecordBase</em> and decorated its properties with the proper ActiveRecord attributes. That is it for the database logic, fast is it not?</p>
<p>Then I created the controller for the log entries. I simply created a class, derived it from <em>Controller</em> and added the <em>Scaffolding</em> attribute to it. That took me about a minute to implement.</p>
<p>Finally I needed to do some plumbing: configuration and initialization. That is all. I now have an working application which allows me to list (with pagination!), view, create, update and delete log entries. The design is awful but it good enough for its purpose.</p>
<p>Castle project supports this out of the box which is amazing in my opinion. You can download a sample application <a href="http://www.devatwork.nl/wp-content/uploads/2007/08/logsample.zip" title="click to download">here</a>.</p>
<h2>Sources</h2>
<table border="0" cellpadding="0" cellspacing="2">
<tr>
<td>[<a name="1">1</a>]</td>
<td><a href="http://www.castleproject.org/" title="Castle Project">Castle Project</a></td>
</tr>
<tr>
<td>[<a name="2">2</a>]</td>
<td><a href="http://www.castleproject.org/monorail/index.html" title="Castle MonoRail">Castle MonoRail</a></td>
</tr>
<tr>
<td>[<a name="3">3</a>]</td>
<td><a href="http://www.castleproject.org/activerecord/index.html" title="Castle ActiveRecord">Castle ActiveRecord</a></td>
</tr>
<tr>
<td>[<a name="4">4</a>]</td>
<td><a href="http://en.wikipedia.org/wiki/Active_Record_Pattern" title="Active Record Pattern">Active Record Pattern</a></td>
</tr>
</table>

	Tags: <a href="http://www.devatwork.nl/tag/activerecord/" title="ActiveRecord" rel="tag">ActiveRecord</a>, <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/monorail/" title="MonoRail" rel="tag">MonoRail</a>, <a href="http://www.devatwork.nl/tag/mvc/" title="MVC" rel="tag">MVC</a>, <a href="http://www.devatwork.nl/tag/rapid-application-building/" title="Rapid Application Building" rel="tag">Rapid Application Building</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/08/rapid-application-building/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Castle Windsor Component Messaging: Senders &amp; Receivers</title>
		<link>http://www.devatwork.nl/2007/06/castle-windsor-component-messaging-senders-receivers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=castle-windsor-component-messaging-senders-receivers</link>
		<comments>http://www.devatwork.nl/2007/06/castle-windsor-component-messaging-senders-receivers/#comments</comments>
		<pubDate>Tue, 12 Jun 2007 20:55:04 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Castle Project]]></category>
		<category><![CDATA[Messaging Facility]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Windsor Container]]></category>
		<category><![CDATA[Inversion of Control]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/06/12/castle-windsor-component-messaging-senders-receivers/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>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.</p>
<p>Anyway, enough talk, lets get down to business.</p>
<h2>Implementing a message sender</h2>
<p>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.</p>
<p>Example:</p>
<pre class="brush: csharp; title: ; notranslate">[MessageSender()]
public class TestSender: SenderBase
{
	public void SendMessage()
	{
		TestMessage msg = new TestMessage();
		base.DoSend(msg);
	}
}</pre>
<p>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.</p>
<h2>Implementing a message receiver</h2>
<p>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.</p>
<p>Example:</p>
<pre class="brush: csharp; title: ; notranslate">[MessageReceiver()]
public class TestReceiver: IMessageReceiver
{
	public void Receive(IMessage message)
	{
		// do something with the message
	}
}</pre>
<p>The receive function will be called when a message is received.</p>
<p>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.</p>

	Tags: <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/inversion-of-control/" title="Inversion of Control" rel="tag">Inversion of Control</a>, <a href="http://www.devatwork.nl/tag/windsor-container/" title="Windsor Container" rel="tag">Windsor Container</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/06/castle-windsor-component-messaging-senders-receivers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internal Messaging for Castle IoC Components</title>
		<link>http://www.devatwork.nl/2007/06/internal-messaging-for-castle-ioc-components/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=internal-messaging-for-castle-ioc-components</link>
		<comments>http://www.devatwork.nl/2007/06/internal-messaging-for-castle-ioc-components/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 09:37:04 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Castle Project]]></category>
		<category><![CDATA[Messaging Facility]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Windsor Container]]></category>
		<category><![CDATA[Inversion of Control]]></category>
		<category><![CDATA[MicroKernel]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/06/01/internal-messaging-for-castle-ioc-components/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Firs we will create a message and its payload:</p>
<pre class="brush: csharp; title: ; notranslate">// creating the message and it's payload
Person person1			= new Person(&amp;amp;amp;quot;Bert&amp;amp;amp;quot;);
IContentMetaInfo metaInfo1	= new ContentMetaInfoBase(typeof(Person));
IContent content1			= new ContentBase(person1, metaInfo1);
Person person2			= new Person(&amp;amp;amp;quot;Trilobyte&amp;amp;amp;quot;);
IContentMetaInfo metaInfo2	= new ContentMetaInfoBase(typeof(Person));
IContent content2			= new ContentBase(person2, metaInfo2);
MessageBase msg			= new MessageBase(new IContent[] {content1,content2});</pre>
<p>Image the message is send to somewhere and then take a look at the receive code below:</p>
<pre class="brush: csharp; title: ; notranslate">// 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);
}</pre>
<p>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.</p>
<p>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.</p>
<p>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!</p>

	Tags: <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/inversion-of-control/" title="Inversion of Control" rel="tag">Inversion of Control</a>, <a href="http://www.devatwork.nl/tag/microkernel/" title="MicroKernel" rel="tag">MicroKernel</a>, <a href="http://www.devatwork.nl/tag/windsor-container/" title="Windsor Container" rel="tag">Windsor Container</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/06/internal-messaging-for-castle-ioc-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inversion of Control</title>
		<link>http://www.devatwork.nl/2007/03/inversion-of-control/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inversion-of-control</link>
		<comments>http://www.devatwork.nl/2007/03/inversion-of-control/#comments</comments>
		<pubDate>Mon, 26 Mar 2007 17:47:48 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Castle Project]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Windsor Container]]></category>
		<category><![CDATA[Inversion of Control]]></category>
		<category><![CDATA[MicroKernel]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/03/26/inversion-of-control/</guid>
		<description><![CDATA[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. Om maar bij het begin te beginnen: Wat is Inversion of Control? IoC wordt meestal gebruikt in een raamwerk om deze uitbreidbaar te maken voor [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p><span id="more-16"></span></p>
<p><strong>Om  maar bij het begin te beginnen: Wat is Inversion of Control?</strong><br />
IoC wordt meestal gebruikt in een raamwerk om deze uitbreidbaar te maken voor ontwikkelaars. Het basis principe is dat het raamwerk weet van de uitbreidingen en deze zelf aanroept. Dit in tegenstelling tot de traditionele API waar de uitbreiding ontwikkelaar het raamwerk aanroept. Dat betekent concreet dat het raamwerk de baas is. Oftewel de rollen zijn omgedraaid.Voor andere definities, zie bronner: [<a href="#1">1</a>], [<a href="#3">3</a>] en [<a href="#4">4</a>].</p>
<p><strong>Inversion of Control container?</strong><br />
Het IoC patroon wordt meestal geÃ¯mplementeerd met behulp van een IoC container. Deze container bevat een register van alle componenten in het hele systeem. Dit register is verantwoordelijk voor het creÃ«ren en opruimen van de componenten als ook het bijhouden van de configuratie en de afhankelijkheden van andere componenten. Dit reduceert de koppeling tussen de diverse component, met als gevolg dat ze makkelijker herbruikbaar, te onderhouden en te testen zijn.</p>
<p>Zoals je misschien hebt opgemerkt maakt de IoC container gebruik van het Dependency Injection patroon om de componenten zo los mogelijk van elkaar te houden.</p>
<p><strong>Waarom is IoC zo geweldig?</strong><br />
IoC stelt je als ontwikkelaar in staat om gemakkelijk afhankelijkheden en configuratie te beheren Doordat koppelingen voorkomen kunnen worden, kan de ontwikkelaar zich richten op zijn eigen taak zonder zich druk hoeft te maken over allerlei afhankelijkheden. Het onderhouden en testen van code is eenvoudiger en ook kunnen componenten gemakkelijker opnieuw gebruikt worden.</p>
<p>Doordat afhankelijkheden in de configuratie geregeld worden, kun je als applicatie beheerder gemakkelijk onderdelen vervangen door andere onderdelen zonder dat er een programmeur aan te pas hoeft te komen.</p>
<p>Dit alles heeft tot gevolg dat softwareprojecten eenvoudiger worden en met grotere zekerheid uitgevoerd kunnen worden, iets waar iedereen voordeel van heeft.</p>
<p><strong>Welke IoC container te gebruiken?</strong><br />
Er zijn verschillende implementaties van IoC containers voor verschillende platformen. Zelf gebruik ik WindsorContainer uit het Castle Project [<a href="#2">2</a>]. Deze container werkt op het .NET platform, mijn favoriete ontwikkelomgeving. Ik ben er pas een aantal weken mee aan het werk en ik ving het geweldig werken, nou zal ik niet beweren dat Windsor de beste is omdat het de enige IoC container is die ik tot nog toe gebruikt heb.</p>
<p>Mocht iemand ervaring hebben met een andere IoC containers, geef dan je mening in een reactie op deze post.</p>
<p>Op de wikipedia pagina over IoC [<a href="#1">1</a>] staat een overzicht van een aantal IoC containers gesorteerd op platform en taal.</p>
<p><strong>Voorbeeld:</strong><br />
Het onderstaande voorbeeld maakt gebruik van de WindsorContainer van het Castle Project. Het is een eenvoudig voorbeeld puur gericht om het IoC principe te demostreren. De onderstaande code is ook niet compleet. Klik <a href="http://www.devatwork.nl/wp-content/uploads/2007/03/iocsample.zip">hier</a> om de hele code te downloaden.</p>
<p>Klasse diagram van het model:</p>
<p><img src="http://www.devatwork.nl/wp-content/uploads/2007/03/ioc.jpg" alt="IoC Classes" id="image19" /></p>
<p>Configuratie:</p>
<p><img src="http://www.devatwork.nl/wp-content/uploads/2007/03/config.gif" alt="IoC Config" id="image18" /></p>
<p>De configuratie specificeert twee componenten: De MessageFactory en de SmtpSender. De SmtpSender wordt geinitialiseerd met de gespecificeerde host name en port (zie constructor van de SmtpSender klasse).</p>
<p>Code:</p>
<p><img src="http://www.devatwork.nl/wp-content/uploads/2007/03/code.gif" alt="IoC Code" id="image17" /></p>
<p>De code is, zoals je kunt zien, erg eenvoudig. De code bestaat uit een viertal delen: Het eerste deel creÃ«ert en configureert de IoC container. Het volgende code gedeelte bestaat uit twee stappen: Het ophalen van de IMessageFactory implementatie klasse uit de IoC container en het creÃ«ren van het bericht. Het derde deel haalt eerst de IMessageSender implementatie klasse op, om vervolgens daarmee het bericht te versturen. En tot slot het laatste deel dat niks anders doet dan opruimen. Dat is alles!</p>
<p>Inversion of Control is, naar mijn mening, een krachtig principe dat er voor zorgt dat je op een totaal andere manier software gaat ontwikkelen. Het ontwikkelen met behulp van het IoC principe even wennen is, het vergt namelijk een andere denkwijze, maar mijn ervaring is dat je na een paar kleine test applicaties, je het principe goed onder de knie hebt en de kracht optimaal kan benutten.</p>
<p>Dat is het wel weer voor deze post, en volgende posts over dit onderwerp zal ik wat meer op de details ingaan. Ik hoop dat je deze post leuk en nuttig vond om te lezen! Als je nog vragen of opmerkingen hebt dan hoor ik het graag!</p>
<p><strong>Bronnen</strong></p>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>[<a title="1" name="1"></a>1]</td>
<td><a href="http://en.wikipedia.org/wiki/Inversion_of_control">Wikepedia over Inversion of Control</a></td>
</tr>
<tr>
<td>[<a title="2" name="2"></a>2]</td>
<td><a href="http://www.castleproject.org/">Castle Project</a></td>
</tr>
<tr>
<td>[<a title="3" name="3"></a>3]</td>
<td><a href="http://www.betaversion.org/~stefano/linotype/news/38/">Stefano Mazzocchi over Inversion of Control</a></td>
</tr>
<tr>
<td>[<a title="4" name="4"></a>4]</td>
<td><a href="http://www.martinfowler.com/articles/injection.html">Martin Fowler over Inversion of Control</a></td>
</tr>
</table>

	Tags: <a href="http://www.devatwork.nl/tag/castle-project/" title="Castle Project" rel="tag">Castle Project</a>, <a href="http://www.devatwork.nl/tag/inversion-of-control/" title="Inversion of Control" rel="tag">Inversion of Control</a>, <a href="http://www.devatwork.nl/tag/microkernel/" title="MicroKernel" rel="tag">MicroKernel</a>, <a href="http://www.devatwork.nl/tag/windsor-container/" title="Windsor Container" rel="tag">Windsor Container</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/03/inversion-of-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

