<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Advanced Unity: Connecting Implementations to Open Generic Types</title>
	<atom:link href="http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=advanced-unity-connecting-implementations-to-open-generic-types</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 18:54:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: Elegant Code &#187; Event Driven Architecture: Publishing Events using an IOC container</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-52507</link>
		<dc:creator>Elegant Code &#187; Event Driven Architecture: Publishing Events using an IOC container</dc:creator>
		<pubDate>Thu, 07 Jan 2010 00:29:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-52507</guid>
		<description>[...] my last post I talked about advanced IOC usage and how it is possible to use an IOC container to resolve and [...]</description>
		<content:encoded><![CDATA[<p>[...] my last post I talked about advanced IOC usage and how it is possible to use an IOC container to resolve and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tramp</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51787</link>
		<dc:creator>Tramp</dc:creator>
		<pubDate>Wed, 23 Dec 2009 12:57:21 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51787</guid>
		<description>Hi Jarod,
you can also have a look at this library - http://autoregistration.codeplex.com/ (looks like it contains what you&#039;re implementing and some more features that may be handy).</description>
		<content:encoded><![CDATA[<p>Hi Jarod,<br />
you can also have a look at this library &#8211; <a href="http://autoregistration.codeplex.com/" rel="nofollow">http://autoregistration.codeplex.com/</a> (looks like it contains what you&#8217;re implementing and some more features that may be handy).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Szymon Kulec</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51655</link>
		<dc:creator>Szymon Kulec</dc:creator>
		<pubDate>Sun, 20 Dec 2009 10:53:39 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51655</guid>
		<description>&lt;a href=&quot;#comment-51636&quot; rel=&quot;nofollow&quot;&gt;@Jarod Ferguson&lt;/a&gt; 
Thank you for your answer. Your solution does make sense:) I could even imagine wiring this using an explicit interface like: IRaiseBaseTypeMessage for a message type but then, it would be (once again) not explicit in terms of handlers as the information would be stored in definition of the message type. To sum up: IF &quot;it&#039;s important for the domain event/message to be explicit&quot; THEN your proposal is truly correct :)</description>
		<content:encoded><![CDATA[<p><a href="#comment-51636" rel="nofollow">@Jarod Ferguson</a><br />
Thank you for your answer. Your solution does make sense:) I could even imagine wiring this using an explicit interface like: IRaiseBaseTypeMessage for a message type but then, it would be (once again) not explicit in terms of handlers as the information would be stored in definition of the message type. To sum up: IF &#8220;it&#8217;s important for the domain event/message to be explicit&#8221; THEN your proposal is truly correct <img src='http://elegantcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarod Ferguson</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51636</link>
		<dc:creator>Jarod Ferguson</dc:creator>
		<pubDate>Sun, 20 Dec 2009 02:27:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51636</guid>
		<description>@Szymon You could extend the API to register the base types of &#039;closedType&#039; to the same handler if you wanted. I do not use inheritance for my domain events, ever. In my opinion, when using a list based router its important for the domain event/message to be explicit. Sematically these are two different &#039;events&#039;, its either AbnormalOrderCanceled or its OrderCanceled, not both.

In your scenario I would have different handlers for both events. If an AbnormalOrderCanceled also needed to run the OrderCanceled Handlers, I would just publish the OrderCanceled event in AbnormalOrderCanceled Handler. An added benefit is that I have more control over whether to proceed to the next step. This quickly gets in to more elegant workflow solutions such as routing slips and sagas. 

Some psuedo code: (this impl is beyond this post and more service bus specific. hopefully it is useful for some)

public class AbnormalOrderCanceledHandler : Handler&lt;AbnormalOrderCanceledMessage&gt;
{
    //pretty much all handlers get a reference back to the bus
    IServiceBus _serviceBus;

    AbnormalOrderCanceledHandler(IServiceBus serviceBus)
    {
	_serviceBus = serviceBus
    }

    public void Handle(AbnormalOrderCanceledMessage message)
    {
        // The abnormal parts of this event were handled successfully
	// so move on to OrderCanceled
	OrderCanceledMessage orderCancelledMessage = new OrderCanceledMessageBuilder(message); 
	_serviceBus.Publish(orderCancelledMessage);
    }
}</description>
		<content:encoded><![CDATA[<p>@Szymon You could extend the API to register the base types of &#8216;closedType&#8217; to the same handler if you wanted. I do not use inheritance for my domain events, ever. In my opinion, when using a list based router its important for the domain event/message to be explicit. Sematically these are two different &#8216;events&#8217;, its either AbnormalOrderCanceled or its OrderCanceled, not both.</p>
<p>In your scenario I would have different handlers for both events. If an AbnormalOrderCanceled also needed to run the OrderCanceled Handlers, I would just publish the OrderCanceled event in AbnormalOrderCanceled Handler. An added benefit is that I have more control over whether to proceed to the next step. This quickly gets in to more elegant workflow solutions such as routing slips and sagas. </p>
<p>Some psuedo code: (this impl is beyond this post and more service bus specific. hopefully it is useful for some)</p>
<p>public class AbnormalOrderCanceledHandler : Handler<abnormalordercanceledmessage><br />
{<br />
    //pretty much all handlers get a reference back to the bus<br />
    IServiceBus _serviceBus;</p>
<p>    AbnormalOrderCanceledHandler(IServiceBus serviceBus)<br />
    {<br />
	_serviceBus = serviceBus<br />
    }</p>
<p>    public void Handle(AbnormalOrderCanceledMessage message)<br />
    {<br />
        // The abnormal parts of this event were handled successfully<br />
	// so move on to OrderCanceled<br />
	OrderCanceledMessage orderCancelledMessage = new OrderCanceledMessageBuilder(message);<br />
	_serviceBus.Publish(orderCancelledMessage);<br />
    }<br />
}</abnormalordercanceledmessage></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarod Ferguson</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51635</link>
		<dc:creator>Jarod Ferguson</dc:creator>
		<pubDate>Sun, 20 Dec 2009 02:24:26 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51635</guid>
		<description>@Jeremy thank you for your input, the base class and abstract class scenarios are especially worth pointing out. Honestly I have not had to deal with those cases. I just stick to a simple Interface&lt;T&gt; convention for messaging/domain events. This impl seems to solve my problems. 

I can understand there is certainly quite a bit more to worry about when building a framework like SM. 

</description>
		<content:encoded><![CDATA[<p>@Jeremy thank you for your input, the base class and abstract class scenarios are especially worth pointing out. Honestly I have not had to deal with those cases. I just stick to a simple Interface<t> convention for messaging/domain events. This impl seems to solve my problems. </p>
<p>I can understand there is certainly quite a bit more to worry about when building a framework like SM.</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Szymon Kulec</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51632</link>
		<dc:creator>Szymon Kulec</dc:creator>
		<pubDate>Sun, 20 Dec 2009 00:33:36 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51632</guid>
		<description>Hello,
what about registering the same handler for subtypes of OrderCanceledMessage, like imaginary AbnormalOrderCanceledMessage? Shouldn&#039;t the same handler be used for them as well, or maybe you want it to be as explicit as it can be (with no handling of message&#039;s subtypes):&gt;</description>
		<content:encoded><![CDATA[<p>Hello,<br />
what about registering the same handler for subtypes of OrderCanceledMessage, like imaginary AbnormalOrderCanceledMessage? Shouldn&#8217;t the same handler be used for them as well, or maybe you want it to be as explicit as it can be (with no handling of message&#8217;s subtypes):&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy D. Miller</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51586</link>
		<dc:creator>Jeremy D. Miller</dc:creator>
		<pubDate>Sat, 19 Dec 2009 03:48:04 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51586</guid>
		<description>Jarod,

Watch your check in RegisterClosedImpl.  The code is too naive.  Sometimes IsGenericType doesn&#039;t work and you also need to check to see if it has generic parameters.  Plus, you need to walk it up the base type tree.  Plus, you need to consider if the open type is an abstract class instead of an interface.  I had to patch some of this on SM tonight.

I will say though, that this is NOT a full equivalent to the SM conventional registration.  Consider your effort with the Unity way versus the StructureMap Convention method.  Advantage StructureMap;-)</description>
		<content:encoded><![CDATA[<p>Jarod,</p>
<p>Watch your check in RegisterClosedImpl.  The code is too naive.  Sometimes IsGenericType doesn&#8217;t work and you also need to check to see if it has generic parameters.  Plus, you need to walk it up the base type tree.  Plus, you need to consider if the open type is an abstract class instead of an interface.  I had to patch some of this on SM tonight.</p>
<p>I will say though, that this is NOT a full equivalent to the SM conventional registration.  Consider your effort with the Unity way versus the StructureMap Convention method.  Advantage StructureMap;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: woro</title>
		<link>http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/comment-page-1/#comment-51581</link>
		<dc:creator>woro</dc:creator>
		<pubDate>Sat, 19 Dec 2009 00:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2009/12/18/advanced-unity-connecting-implementations-to-open-generic-types/#comment-51581</guid>
		<description>I think this post http://marcinbudny.blogspot.com/2009/11/unity-auto-registration.html is closely related to yours and might be also interesting.</description>
		<content:encoded><![CDATA[<p>I think this post <a href="http://marcinbudny.blogspot.com/2009/11/unity-auto-registration.html" rel="nofollow">http://marcinbudny.blogspot.com/2009/11/unity-auto-registration.html</a> is closely related to yours and might be also interesting.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

