<?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: Strengthening your domain: Domain Events</title>
	<atom:link href="http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Wed, 22 May 2013 13:39:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Gary Brunton</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2336</link>
		<dc:creator>Gary Brunton</dc:creator>
		<pubDate>Fri, 18 Jun 2010 17:46:53 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2336</guid>
		<description>Just came across another way to define the DomainEvents static class that I like more:

public static class DomainEvents
{
  private static IContainer container;

  public static void Initialize(IContainer newContainer)
  {
    if (newContainer == null) throw new ArgumentNullException(&quot;newContainer&quot;);
    container = newContainer;
  }

  public static void Register&lt;T&gt;(Action&lt;T&gt; callback) where T : IDomainEvent
  {
    container.GetInstance&lt;IDomainEventsController&gt;().Register(callback);
  }

  public static void ClearCallbacks()
  {
    container.GetInstance&lt;IDomainEventsController&gt;().ClearCallbacks();
  }

  public static void Raise&lt;T&gt;(T domainEvent) where T : IDomainEvent
  {
    container.GetInstance&lt;IDomainEventsController&gt;().Raise(domainEvent);
  }
}


I got the idea from here:
http://jasondentler.com/blog/2009/11/simple-domain-events/

I like it better because I don&#039;t have to use the static ObjectFactory class explicitly.  Any thoughts on this?</description>
		<content:encoded><![CDATA[<p>Just came across another way to define the DomainEvents static class that I like more:</p>
<p>public static class DomainEvents<br />
{<br />
  private static IContainer container;</p>
<p>  public static void Initialize(IContainer newContainer)<br />
  {<br />
    if (newContainer == null) throw new ArgumentNullException(&#8220;newContainer&#8221;);<br />
    container = newContainer;<br />
  }</p>
<p>  public static void Register<t>(Action</t><t> callback) where T : IDomainEvent<br />
  {<br />
    container.GetInstance<idomaineventscontroller>().Register(callback);<br />
  }</p>
<p>  public static void ClearCallbacks()<br />
  {<br />
    container.GetInstance</idomaineventscontroller><idomaineventscontroller>().ClearCallbacks();<br />
  }</p>
<p>  public static void Raise<t>(T domainEvent) where T : IDomainEvent<br />
  {<br />
    container.GetInstance<idomaineventscontroller>().Raise(domainEvent);<br />
  }<br />
}</p>
<p>I got the idea from here:<br />
<a href="http://jasondentler.com/blog/2009/11/simple-domain-events/" rel="nofollow">http://jasondentler.com/blog/2009/11/simple-domain-events/</a></p>
<p>I like it better because I don&#8217;t have to use the static ObjectFactory class explicitly.  Any thoughts on this?</idomaineventscontroller></t></idomaineventscontroller></t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2335</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 16 Jun 2010 12:48:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2335</guid>
		<description>@Gary

Looks cool!  Yeah, the nested container is just a way to provide scoped lifecycle of things.  Great for context objects, and can be used instead of Hybrid stuff in some places.</description>
		<content:encoded><![CDATA[<p>@Gary</p>
<p>Looks cool!  Yeah, the nested container is just a way to provide scoped lifecycle of things.  Great for context objects, and can be used instead of Hybrid stuff in some places.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Brunton</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2334</link>
		<dc:creator>Gary Brunton</dc:creator>
		<pubDate>Tue, 15 Jun 2010 20:46:19 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2334</guid>
		<description>This might be lame but I think I like it....

public static class DomainEvents
{
    public static void Register&lt;T&gt;(Action&lt;T&gt; callback) where T : IDomainEvent
    {
        ObjectFactory.GetInstance&lt;DomainEventsController&gt;().Register(callback);
    }

    public static void ClearCallbacks()
    {
        ObjectFactory.GetInstance&lt;DomainEventsController&gt;().ClearCallbacks();
    }

    public static void Raise&lt;T&gt;(T domainEvent) where T : IDomainEvent
    {
        ObjectFactory.GetInstance&lt;DomainEventsController&gt;().Raise(domainEvent);
    }
}

Where the DomainEventsController (for lack of a better word) is the DomainEvents implementation and can be wired up as having a Hybrid lifecyle.  I was also thinking that using ObjectFactory.TryGetInstance&lt;DomainEventsController&gt; could be used instead of GetInstance.  This could give us more flexibility within our tests.

You got me thinking about nested containers now.  I&#039;ve been using the Hybrid lifecycle.  Wonder if I&#039;m doing that wrong?

Any ideas?
</description>
		<content:encoded><![CDATA[<p>This might be lame but I think I like it&#8230;.</p>
<p>public static class DomainEvents<br />
{<br />
    public static void Register<t>(Action</t><t> callback) where T : IDomainEvent<br />
    {<br />
        ObjectFactory.GetInstance<domaineventscontroller>().Register(callback);<br />
    }</p>
<p>    public static void ClearCallbacks()<br />
    {<br />
        ObjectFactory.GetInstance</domaineventscontroller><domaineventscontroller>().ClearCallbacks();<br />
    }</p>
<p>    public static void Raise<t>(T domainEvent) where T : IDomainEvent<br />
    {<br />
        ObjectFactory.GetInstance<domaineventscontroller>().Raise(domainEvent);<br />
    }<br />
}</p>
<p>Where the DomainEventsController (for lack of a better word) is the DomainEvents implementation and can be wired up as having a Hybrid lifecyle.  I was also thinking that using ObjectFactory.TryGetInstance</domaineventscontroller><domaineventscontroller> could be used instead of GetInstance.  This could give us more flexibility within our tests.</p>
<p>You got me thinking about nested containers now.  I&#8217;ve been using the Hybrid lifecycle.  Wonder if I&#8217;m doing that wrong?</p>
<p>Any ideas?<br />
</domaineventscontroller></t></domaineventscontroller></t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2333</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Tue, 15 Jun 2010 12:15:48 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2333</guid>
		<description>@Gary

Funny you should ask this, as we&#039;re looking at the exact same issues.  Static gateways just don&#039;t play as nicely with IoC, so we&#039;re also examining our options.  Right now, domain event handlers are instantiated by the container, so we do have SOME control over lifecycle.

However, we can&#039;t do things like nested containers.</description>
		<content:encoded><![CDATA[<p>@Gary</p>
<p>Funny you should ask this, as we&#8217;re looking at the exact same issues.  Static gateways just don&#8217;t play as nicely with IoC, so we&#8217;re also examining our options.  Right now, domain event handlers are instantiated by the container, so we do have SOME control over lifecycle.</p>
<p>However, we can&#8217;t do things like nested containers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Brunton</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2332</link>
		<dc:creator>Gary Brunton</dc:creator>
		<pubDate>Mon, 14 Jun 2010 15:57:27 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2332</guid>
		<description>Thanks for the excellent series!  I know I&#039;m very late to this discussion but thought I&#039;d ask anyway.

I&#039;m wondering how you manage the shared state (the actions) within the static DomainEvents class for asp .net web applications?  Udi places the  [ThreadStatic] attribute on the actions but this is not a good idea when in the context of an asp .net web application.  I&#039;m thinking of using Structure Map&#039;s ObjectFactory to get the DomainEvents class and have that class wired up with a Hybrid lifecycle.

How do you handle this issue?</description>
		<content:encoded><![CDATA[<p>Thanks for the excellent series!  I know I&#8217;m very late to this discussion but thought I&#8217;d ask anyway.</p>
<p>I&#8217;m wondering how you manage the shared state (the actions) within the static DomainEvents class for asp .net web applications?  Udi places the  [ThreadStatic] attribute on the actions but this is not a good idea when in the context of an asp .net web application.  I&#8217;m thinking of using Structure Map&#8217;s ObjectFactory to get the DomainEvents class and have that class wired up with a Hybrid lifecycle.</p>
<p>How do you handle this issue?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott White</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2331</link>
		<dc:creator>Scott White</dc:creator>
		<pubDate>Wed, 14 Apr 2010 16:19:42 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2331</guid>
		<description>Well for one, avoiding setters can eliminate the possibility of null value properties.

I use protected setters for lists and objects and I do something like this:

private AuditDate _auditDate = new AuditDate();

protected set
{
	if (value == null) throw new ArgumentNullException(&quot;value&quot;);
	_auditDate = value;
}

Eliminates the need to do any null checking, reduces likelyhood of bugs.  In the declaration where I&#039;m instantiating the AuditDate, if the setter was public allowing the caller to set a new object then I would have set the initial value to be a NullAuditDate using the null object pattern.

To me this is the next logical step after protecting your setters.  The objects using the NullObject pattern will always fail persistence since the ORM doesn&#039;t track an object of that type.</description>
		<content:encoded><![CDATA[<p>Well for one, avoiding setters can eliminate the possibility of null value properties.</p>
<p>I use protected setters for lists and objects and I do something like this:</p>
<p>private AuditDate _auditDate = new AuditDate();</p>
<p>protected set<br />
{<br />
	if (value == null) throw new ArgumentNullException(&#8220;value&#8221;);<br />
	_auditDate = value;<br />
}</p>
<p>Eliminates the need to do any null checking, reduces likelyhood of bugs.  In the declaration where I&#8217;m instantiating the AuditDate, if the setter was public allowing the caller to set a new object then I would have set the initial value to be a NullAuditDate using the null object pattern.</p>
<p>To me this is the next logical step after protecting your setters.  The objects using the NullObject pattern will always fail persistence since the ORM doesn&#8217;t track an object of that type.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2330</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 14 Apr 2010 12:35:07 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2330</guid>
		<description>@Scott White

No, not really. What would be the connection?

@ryzam

In my experience, events only arise when someone cares about something that happened.  A command may generate no events, or several, it just really depends on those &quot;When&quot; requirements.</description>
		<content:encoded><![CDATA[<p>@Scott White</p>
<p>No, not really. What would be the connection?</p>
<p>@ryzam</p>
<p>In my experience, events only arise when someone cares about something that happened.  A command may generate no events, or several, it just really depends on those &#8220;When&#8221; requirements.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryzam</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2329</link>
		<dc:creator>ryzam</dc:creator>
		<pubDate>Wed, 14 Apr 2010 06:00:32 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2329</guid>
		<description>Thanks Jimmy

If I&#039;m not mistaken, there was a discussion in DDD group either entity can have reference to repository/service or not. Some of them reject this approach even though if we are using Dependency Injection to supply the instantiate object.

If we look into this Domain Events implementation the concept is almost similar where your entity some how will also have to use external component to do a job.

But, personally I agree with Domain Events solution, keep up ..

Another question, does every command we send to entity need to have DomainEvent?

Example: If we have command RegisterLicenseCustomer, do we also have LicenseCustomerRegistered as DomainEvents?</description>
		<content:encoded><![CDATA[<p>Thanks Jimmy</p>
<p>If I&#8217;m not mistaken, there was a discussion in DDD group either entity can have reference to repository/service or not. Some of them reject this approach even though if we are using Dependency Injection to supply the instantiate object.</p>
<p>If we look into this Domain Events implementation the concept is almost similar where your entity some how will also have to use external component to do a job.</p>
<p>But, personally I agree with Domain Events solution, keep up ..</p>
<p>Another question, does every command we send to entity need to have DomainEvent?</p>
<p>Example: If we have command RegisterLicenseCustomer, do we also have LicenseCustomerRegistered as DomainEvents?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott White</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2328</link>
		<dc:creator>Scott White</dc:creator>
		<pubDate>Wed, 14 Apr 2010 04:44:15 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2328</guid>
		<description>Again great articles.  Was much of this inspired by NullObject pattern?</description>
		<content:encoded><![CDATA[<p>Again great articles.  Was much of this inspired by NullObject pattern?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/#comment-2327</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Tue, 13 Apr 2010 22:32:06 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/04/08/strengthening-your-domain-domain-events.aspx#comment-2327</guid>
		<description>@ryzam

While that&#039;s certainly possible, you&#039;re now coupling yourself to implementations of handlers.  With an event, I don&#039;t need to know who, or how many folks care about this event.</description>
		<content:encoded><![CDATA[<p>@ryzam</p>
<p>While that&#8217;s certainly possible, you&#8217;re now coupling yourself to implementations of handlers.  With an event, I don&#8217;t need to know who, or how many folks care about this event.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
