Note that there are some explanatory texts on larger screens.

plurals
  1. POBreaking the "ubiquitous language" by having an IoC in Domain Model?
    primarykey
    data
    text
    <p>My question is about <a href="http://www.udidahan.com/2009/06/14/domain-events-salvation/" rel="nofollow">Udi's solution</a> to domain events, particularly the class <code>DomainEvents</code> (see code below)</p> <p>An excerpt from Udi's code. It lives domain model as a static class.</p> <pre><code>public static class DomainEvents { [ThreadStatic] //so that each thread has its own callbacks private static List&lt;Delegate&gt; actions; public static IContainer Container { get; set; } //as before //Registers a callback for the given domain event public static void Register&lt;T&gt;(Action&lt;T&gt; callback) where T : IDomainEvent { if (actions == null) actions = new List&lt;Delegate&gt;(); actions.Add(callback); } //Clears callbacks passed to Register on the current thread public static void ClearCallbacks () { actions = null; } //Raises the given domain event public static void Raise&lt;T&gt;(T args) where T : IDomainEvent { if (Container != null) foreach(var handler in Container.ResolveAll&lt;Handles&lt;T&gt;&gt;()) handler.Handle(args); if (actions != null) foreach (var action in actions) if (action is Action&lt;T&gt;) ((Action&lt;T&gt;)action)(args); } } </code></pre> <p>From the code above, the static member <code>IContainer</code> creates an ioc-container-dependency in the domain model. Though I am not really sure if Udi's <code>IContainer</code> is an interface or an actual IoC container.</p> <p>I don't see anything like this in his sample:</p> <pre><code>public interface IContainer { IEnumerable&lt;T&gt; ResolveAll&lt;T&gt;(); } </code></pre> <p>My 1st question is: <strong>What is this <code>IContainer</code> in the <code>DomainEvents</code> class?</strong> If it is truly an IoC container then doesn't it break the rule of <em>"not having an infrastructure in the domain"</em>? (Please correct me if I'm wrong)</p> <p>Isn't the idea of DDD is about separating the infrastructure from the domain? </p> <p>My 2nd question is: <strong>Does <code>DomainEvents</code> itself breaks the rule <em>"ubiquitous language of DDD"</em></strong>? Because it's implementation does not pertain to any domain.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload